Getting Started - Basic Button Project
This is basic; More detail should go here later.
To Do:
- Connect a wire from GND to one side of the button.
- Connect a wire to pin 21
- Put a button on the breadboard.
- Take note that standard buttons are connected on the sides, so they need to span the center of the breadboard.
const int button_pin = 21;
const int light_pin = 2;
void setup() {
// initialize the pushbutton pin as an pull-up input
pinMode(light_pin, OUTPUT);
pinMode(button_pin, INPUT_PULLUP);
}
void loop() {
bool currentState = digitalRead(button_pin);
if (currentState == HIGH) {
digitalWrite(light_pin, HIGH);
} else {
digitalWrite(light_pin, LOW);
}
}