Good Evening All
I am attempting to turn on 4 leds in sequence eventually if I manage to sort my code I will be using a 8 ch Relay module relay board that is why I have the leds turning on with a LOW signal
I have used led 3 as a marker as soon as the code is loaded into the Arduino Nano led 3 is turned and then I use a stopwatch to chec the timing leds 4,5,6 turn on after 1,2,3 minutes respectively however led 7 instead of coming on after 4 minutes it takes 6 minutes to come on I changed the delay time on pin 7 to 7 minutes the led came on after 9 minutes..
I would appreciate if a forum member could tell me where I am going wrong with my code
Thanks oldguyjn
unsigned long timer4 =0;
unsigned long timer5= 0;
unsigned long timer6= 0;
unsigned long timer7= 0;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
}
void loop() {
digitalWrite(3, LOW); //led 3 used as indicator for start of time sequence
if (millis() - timer4 > 1000UL * 60 * 1){
digitalWrite(4, LOW); //led 4 on after 1 minute delay
timer4 = millis();
if (millis() - timer5 > 1000UL * 60 * 2){
digitalWrite(5, LOW); //led 5 on after 2 minute delay
timer5 = millis();
}
if (millis() - timer6 > 1000UL * 60 * 3 ){
digitalWrite(6, LOW); // led 6 on after 3 minute delay
timer6 = millis();
if (millis() - timer7 > 1000UL * 60 * 3to 7minutes) {
digitalWrite(7,LOW);
timer7 = millis(); // led on 7 after 4 minute delay (actual delay is 6 minutes )
}
}
}
}