Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Created November 2, 2020 19:10
Show Gist options
  • Save cbscribe/19e593e5c52df552b7a066861df34d3a to your computer and use it in GitHub Desktop.
Save cbscribe/19e593e5c52df552b7a066861df34d3a to your computer and use it in GitHub Desktop.
Arduino example: LED toggle button
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