/* In this code, for the first five seconds LED1 blinks after every 200
milliseconds while LED2 blinks after every second. In the next five seconds,
this is reversed and LED1 now blinks after every second while LED2 blinks
after every 200 milliseconds. This repeats itself.
*/
uint8_t led1 = 12, led2 = 4;
int previousMillis1 = 0,previousMillis2 = 0 ;
int countA = 0, countB = 0 ;
int delay1 = 200, delay2 = 1000;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
if ((millis()- previousMillis1)> delay1){ // for the first 5seconds LED1 blinks after 200ms
previousMillis1 = millis();
digitalWrite(led1, !digitalRead(led1));
countA++;
}
if (countA == 25){ // for the next 5sec, LED1 blinks after everysecond
delay1 = 1000;
}
if (countA == 30){ // for the next 5sec LED1 blinks after every 200ms
countA = 0; // Count is reset to enable the function to loop
delay1 = 200;
}
if ((millis()- previousMillis2)> delay2){ //for the first 5sec LED2 blinks after every second
previousMillis2 = millis();
digitalWrite(led2, !digitalRead(led2));
countB++;
}
if (countB == 5){ //for the next 5sec LED2 blinks after every 200ms
delay2 = 200;
}
if (countB == 30){ //for the next 5sec LED2 blinks after every second
countB = 0; //Count is reset to enable the function to loop
delay2 = 1000;
}
}