[아두노] 관련 실현

23668 단어 #단편기

LED

class LED {
public:
    LED(int c_leds[], int c_n) {
        leds = c_leds;
        n = c_n;
    };
    void bullet(int speed, char direction) {
        int k = n, t = 0;
        //    
        if (direction == 'L') {
            for (int i = 0;i < n;i++) {
                for (int j = 0;j < k - 1;j++) {
                    digitalWrite(leds[j], HIGH);
                    delay(1000 - speed);
                    digitalWrite(leds[j], LOW);
                }
                digitalWrite(leds[(k--) - 1], HIGH);
            }

            //  
            for(int i=0;i<n;i++){
               digitalWrite(leds[i], LOW);
            }
            //    
        }
        else if (direction == 'R') {
            for (int i = 0;i < n;i++) {
                for (int j = k - 1;j >= t;j--) {
                    digitalWrite(leds[j], HIGH);
                    delay(1000 - speed);
                    digitalWrite(leds[j], LOW);
                }
                digitalWrite(leds[t++], HIGH);
            }
            //  
            for(int i=0;i<n;i++){
               digitalWrite(leds[i], LOW);
            }
            
            
        }
    }

    void waterfall(int speed, char direction) {

        //    
        if (direction == 'L') {
            for (int i = 0;i < n;i++) {
                digitalWrite(leds[i], HIGH);
                delay(1000 - speed);
                digitalWrite(leds[i], LOW);
            }
            //    
        }
        else if (direction == 'R') {
            for (int i = n;i >= 0;i--) {
                digitalWrite(leds[i], HIGH);
                delay(1000 - speed);
                digitalWrite(leds[i], LOW);
            }
        }
    }

private:
    int* leds, n;
};

총알 효과

void led_bullet(int leds[],int n,int speed,char direction){
     int k = n,t=0;
     //    
     if(direction == 'L'){
     for(int i=0;i<n;i++){
        for(int j=0;j<k-1;j++){
            digitalWrite(leds[j],HIGH);
            delay(1000-speed);
            digitalWrite(leds[j],LOW);
         }   
            digitalWrite(leds[(k--)-1],HIGH);
       }
       //    
       }else if(direction == 'R'){
           for(int i=0;i<n;i++){
              for(int j=k-1;j>=t;j--){
                  digitalWrite(leds[j],HIGH);
                  delay(1000-speed);
                  digitalWrite(leds[j],LOW);
               }   
                  digitalWrite(leds[t++],HIGH);
             }
         }
}

유수등 효과

void led_waterfall(int leds[],int n,int speed,char direction){

       //    
       if(direction == 'L'){
               for(int i=0;i<n;i++){
                 digitalWrite(leds[i],HIGH);
                 delay(1000-speed);
                 digitalWrite(leds[i],LOW);
                }
        //    
    	}else if(direction == 'R'){
             for(int i=n;i>=0;i--){
               digitalWrite(leds[i],HIGH);
               delay(1000-speed);
               digitalWrite(leds[i],LOW);
             }
      }
}

좋은 웹페이지 즐겨찾기