/*
Button
Turns on and off a light emitting diode(LED) connected to digital pin 13,
when pressing a pushbutton attached to pin 4.
The circuit:
- LED attached from pin 13 to ground through 220 ohm resistor
- pushbutton attached to pin 4 from +5V
- 10K resistor attached to pin 4 from ground
- Note: on most Arduinos there is already an LED on the board
attached to pin 13.
*/
//press the blue button to turn on the LED
//Release the blue button to turn off the LED
#define BUTTON_PIN 4
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
// the loop function runs over and over again forever
void loop() {
int value = digitalRead((BUTTON_PIN));
if (value == HIGH) {
digitalWrite(LED_BUILTIN, LOW);
}
if (value == LOW) {
digitalWrite(LED_BUILTIN, HIGH);
}
}