Last active
June 26, 2020 13:10
-
-
Save lean8086/a61e24e691c4ef18839859e4c36dabf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int BUTTON_PIN = 2; | |
// The setup function runs once when you press reset or power the board | |
void setup() { | |
// Initialize button pin as a pull-up input. | |
pinMode(BUTTON_PIN, INPUT_PULLUP); | |
// Initialize digital pin LED_BUILTIN as an output. | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
// The loop function runs over and over again forever | |
void loop() { | |
// Get the digital state from the button pin | |
// In pull-up inputs the button logic is inverted (HIGH is not pressed, LOW is pressed) | |
int buttonState = digitalRead(BUTTON_PIN); | |
// Turn on/off the LED depending on the button state | |
if (buttonState == LOW) { | |
digitalWrite(LED_BUILTIN, HIGH); | |
} else { | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment