Imitaremos el coche fantástico con una secuencia de 6 leds.
¿QUÉ NECESITAREMOS?
- 6 LEDS.
int timer = 100;
int ledPins[] = { 2, 3, 4, 5, 6, 7 };
int pinCount = 6;
void setup()
{
int thisPin;
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
}
CONEXIÓN:
Los ánodos de cada led irán a los pines 2, 3 , 4, 5, 6 y 7 y
los cátodos irán conectados a gnd a través de una resistencia de 220Ω.