Paso 2: El código
/********************************************************* * Demonstration using millis() instead of delay() so * another activity can happen within the delay. * * The anode of a red LED is connected to pin 10 with a * resistor in series connected to ground. * * The anode of a green LED is connected to pin 11 with a * resistor in series connected to ground. * * A pushbutton switch is connected to pin 12 and ground. * * The red LED blinks on for one second then off for one * second. * * The green LED lights when the button is pressed. * *********************************************************/ unsigned long time = millis(); int toggle = 1; /********************************************** * setup() function **********************************************/ void setup() { pinMode(10, OUTPUT); //Red LED pinMode(11, OUTPUT); //Green LED pinMode (12, INPUT_PULLUP); //Switch digitalWrite(10, HIGH); //Initial state of red LED } /********************************************** * loop() function **********************************************/ void loop() { if(millis()-time > 1000) //Has one second passed? { toggle = !toggle; //If so not toggle digitalWrite(10, toggle); //toggle LED time = millis(); //and reset time. } digitalWrite(11, !digitalRead(12)); //Light green LED if Button pressed. }