Paso 2: Paso 2. Botón de control LED
<p>/*<br> PART2 BUTTON CONTROL LED Press the button, led ON, press again led OFF */ int led = 5; // The D5 pin,driving LED int button = A0; // The A0,read the button,Here used a analog pin as digital pin. void setup() { pinMode(led, OUTPUT); // initialize the LED pin as an output. pinMode(button, INPUT_PULLUP);// initialize the BUTTON pin as an input. } void loop() { if(digitalRead(button)==LOW){ delay(200); // wait for 200 microsecond,Avoid pressing the button and read many times in this very short time digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) while(1){ if(digitalRead(button)==LOW){ delay(200); digitalWrite(led, LOW); // turn the LED off (LOW is the voltage level) break; //End of the while loop,Back to the main loop }} }}</p>