Tässä olisi yksi vaihtoehtoinen tapa hoitaa tuo homma.
Vilkkuminen tapahtuu seuraavan kaavion mukaan:
1 led 1s taukoa 1s palaa.......loop
2 led 2s taukoa 1s palaa.......loop
3 led 3s taukoa 1s palaa.......loop
4 led 4s taukoa 1s palaa.......loop
Silmukassa käytetään laskuria ja tutkitaan jakojäännöstä jonka perusteella ledit sytytetään ja niitä pidetään päällä yksi sekunti.
Koodi:
int count = 0;
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 10; thisPin < 14; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
count++;
// Turn LEDs on individually...
if (count % 2 == 0)
digitalWrite(10, HIGH);
if (count % 3 == 0)
digitalWrite(11, HIGH);
if (count % 4 == 0)
digitalWrite(12, HIGH);
if (count % 5 == 0)
digitalWrite(13, HIGH);
// Sleep 1s with specific LEDs ON
delay(1000);
// Turn all LEDs OFF
for (int thisPin = 10; thisPin < 14; thisPin++) {
digitalWrite(thisPin, LOW);
}
}