Código Robotic 3 Intermedio – Pag58
1 int pinArray [] = {2,3,4,5,6,7,8,9,10,11,12,13 }; // Vector donde se van a declarar los LEDs
2 int waitStart = 200; // Tiempo entre encender un LED y otro
3 int tailLength = 4; // Numero de LEDs activos
4 int lineSize = 12; // Numero total de LEDs
5
6 void setup()
7 {
8 int i;
9 for (i=0; i< lineSize; i++)
10 {
11 pinMode(pinArray[i], OUTPUT);
12 }
13 }
14
15 void loop()
16 {
17 int i;
18 int tailCounter = tailLength; // Configuré la longitud de la cola en un contador.
19 for (i=0; i<lineSize; i++)
20 {
21 digitalWrite(pinArray[i],HIGH); // Encender consecutivamente los LEDs
22 delay(waitStart); // variable de tiempo para controlar qué tan rápido enciende los lEDs
23 if (tailCounter == 0)
24 {
25 digitalWrite(pinArray[i-tailLength],LOW); // Apago los LED dependiendo de mi tailLength
26 }
27 else
28 if (tailCounter > 0)
29 tailCounter--;
30 }
31 for (i=(lineSize-tailLength); i<lineSize; i++)
32 {
33 digitalWrite(pinArray[i],LOW); // Apagar los LEDs
34 delay(waitStart); // Esta variable de tiempo controla qué tan rápido los enciendo, y también los apago.
35 }
36 }
