int ledPin[] = {13, 12, 11,10};
int ledDelay[4]={8000, 4000,2000, 1000};
// declare other required variables
unsigned long lastChangeTime[4];
int ledState[4];
unsigned long currTime;
void setup() {
currTime =0;
for(int i=0;i<4;i++){
// initialize lastChangeTimes
lastChangeTime[i] = 0;
ledState[i] = LOW;
pinMode(ledPin[i], OUTPUT);
digitalWrite(ledPin[i], ledState[i]);
}
}
void loop() {
// implement the toggling logic
currTime = millis();
for (int i = 0; i < 4; i++) {
if (currTime - lastChangeTime[i] >= ledDelay[i]) {
ledState[i] = !ledState[i];
digitalWrite(ledPin[i], ledState[i]);
lastChangeTime[i] = currTime;
}
}
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6