Standard semi newbie disclaimer....
I'm trying to do something relatively simple, and getting stuck. My goal is to have a simple 1-2-3-1-2-3-1-2-3... chaser of 3 LEDs. I can do this using a delay function easily, but want to use a millis() type solution like Blink Without Delay. So, in short;
All LEDs off
Turn on LED 1,
check to see if fixed interval passed
if true, turn off LED 1, turn LED 2 on
Check timer
if true, turn off LED 1, 2, turn LED 3 on
My current code example only turns on the fisrt LED constantly:
/*This sketch borrows the array setup from the 5 random blink
without sketch
*/
const int numberOfBlades = 3;
int ledPin[] = { 6, 7, 9}; // LED pins to use.
int ledState[3];
long interval = 83;
long previousMillis = 0; // will store last time LED was updated
int i = 0;
void setup() {
for(int i = 0; i<numberOfBlades; i++){
pinMode(ledPin[i],OUTPUT);
ledState[i] = LOW;
digitalWrite(ledPin[i], LOW); // all LEDs off
}
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) { // Arduino run time - changeTime value greater then ledDelay variable? Yes then
previousMillis = currentMillis;
changeLED(); // Go to changeLED routine.
i = i++ % 2; //i is either 0, 1 or 2
}
}
void changeLED(){
for(; ;){
if (i % 0 == 0){
ledState[0] = HIGH;
ledState[1] = LOW;
ledState[2] = LOW;
digitalWrite(ledPin[i],ledState[i]);
}
else if (i % 1 == 0){
ledState[0] = LOW;
ledState[1] = HIGH;
ledState[2] = LOW;
digitalWrite(ledPin[i],ledState[i]);
}
else (i % 2 == 0); {
ledState[0] = LOW;
ledState[1] = LOW;
ledState[2] = HIGH;
digitalWrite(ledPin[i],ledState[i]);
}
}
}
Any help appreciated!