Created
November 2, 2020 19:10
-
-
Save cbscribe/19e593e5c52df552b7a066861df34d3a to your computer and use it in GitHub Desktop.
Arduino example: LED toggle button
This file contains hidden or 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
void setup() | |
{ | |
pinMode(12, OUTPUT); | |
pinMode(2, INPUT_PULLUP); | |
} | |
int button; | |
int last_button; | |
int led = LOW; | |
void loop() | |
{ | |
last_button = button; | |
button = digitalRead(2); | |
if (button == LOW && last_button == HIGH) | |
{ | |
led = !led; | |
} | |
digitalWrite(12, led); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment