본문 바로가기

Arduino

RGB_Blink

superloop.ino

void setup() {
  blink_setup();
  fading_setup();
  blinkRGB_setup();
  //fadingRGB_setup();
}

void loop() {
  blink_loop();
  fading_loop();
  blinkRGB_loop();
  //fadingRGB_loop();
}

blinkRGB.ino

unsigned long rgb_prevTime[3]={0};
unsigned long rgb_interval[3]={1000,2000,3000};
int rgb_pin[3]={12,7,8};
int rgb_state[3]={LOW,LOW,LOW};

void blinkRGB_setup(){
    for(int i=0;i<3;i++){
      pinMode(rgb_pin[i],OUTPUT);
    }
}

void blinkRGB_loop(){
  unsigned long currTime=millis();
  for(int i=0;i<3;i++){
  if(currTime-rgb_prevTime[i]>=rgb_interval[i]){
    rgb_prevTime[i]=currTime;
    if(rgb_state[i]==LOW){
    rgb_state[i]=HIGH;  
    }else{
      rgb_state[i]=LOW;
    }
    digitalWrite(rgb_pin[i],rgb_state[i]);
  }
  }
}

'Arduino' 카테고리의 다른 글

BT input  (0) 2022.03.15
LED control with SerialRead  (0) 2022.03.14
RGB_fading  (0) 2022.03.11
LED_blink_fading_delay  (0) 2022.03.10
LED_Blink_Fading_millis  (0) 2022.03.10