Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Created April 5, 2021 16:25
Show Gist options
  • Save cbscribe/1266f0685820b0dd1d41aec124e94ef0 to your computer and use it in GitHub Desktop.
Save cbscribe/1266f0685820b0dd1d41aec124e94ef0 to your computer and use it in GitHub Desktop.
Arduino LED button toggle
int button;
int last_button;
int led_state = LOW;
void setup()
{
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);
}
void loop()
{
last_button = button;
button = digitalRead(2);
if (button == LOW && last_button == HIGH)
{
led_state = !led_state;
}
digitalWrite(13, led_state);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment