Paso 3: El código
Copie este código en el IDE de Arduino y subirlo a tu Arduino:
/********************************************************* * Demonstration using millis() instead of delay() so * another activity can happen within the delay. * * The anode of four LEDs are connected to pins 2 - 5. * The cathodes are connected to ground through resistors. * * LEDs are timed to make a binary counter. * *********************************************************/ unsigned long time[4]; //Holds time for each LED. int pin[8] = {2.3.4.5}; //Pin numbers for LEDs. int toggle[8] = {0,0,0,0}; //Toggles for LEDs. (0 or 1) /********************************************** * setup() function **********************************************/ void setup() { for(int i=0;i<4;i++) { pinMode(pin[i], OUTPUT); //Set LED pins as output. digitalWrite(pin[i], LOW); //All LEDs are off at start. time[i] = millis(); //Start timers for all LEDs. } } /********************************************** * loop() function **********************************************/ void loop() { int interval[4]={1000,2000,4000,8000}; for(int i=0;i<4;i++) //For each LED in turn. { if(millis()-time[i] > interval[i]) //Has time passed interval? { toggle[i] = !toggle[i]; //If so not toggle, time[i] = millis(); //reset time, digitalWrite(pin[i], toggle[i]); //and toggle LED, } } }