Hi, I am trying to write a code to turn LED lights on and off with Millis. I cannot use the Blink Without Delay sample because my intervals would be different.
Here's the code I wrote.
int led = 42;
int led2 = 44;
int led3 = 46;
int led4 = 48;
int led5 = 50;
int led6 = 52;
int total = 1580;
int count = 0;
void setup() {
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
}
void loop() {
if(millis() == total*count + 200) {
digitalWrite(led, HIGH);
}
if(millis() == total*count + 350) {
digitalWrite(led2, HIGH);
}
if(millis() == total*count + 550) {
digitalWrite(led3, HIGH);
}
if(millis() == total*count + 630) {
digitalWrite(led4, HIGH);
}
if(millis() == total*count + 830) {
digitalWrite(led5, HIGH);
}
if(millis() == total*count + 880) {
digitalWrite(led6, HIGH);
}
if(millis() == total*count + 1080) {
digitalWrite(led6, LOW);
}
if(millis() == total*count + 1180) {
digitalWrite(led5, LOW);
}
if(millis() == total*count + 1280) {
digitalWrite(led4, LOW);
}
if(millis() == total*count + 1380) {
digitalWrite(led3, LOW);
}
if(millis() == total*count + 1480) {
digitalWrite(led2, LOW);
}
if(millis() == total*count + 1580) {
digitalWrite(led, LOW);
}
count = count + 1;
}
Without the last line "count = count + 1;" The LED lights will turn on but only loop once, which I understand why. But with the last line LED lights won't turn on at all. Can someone please tell me what i'm doing wrong? Using count++; does the same thing.
Also I imagine if I leave it on for too long the count would get too big even with unsigned long. In actuality it probably won't but I just like to know how can I resolve that?
Thank you!