Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Created November 10, 2020 17:21
Show Gist options
  • Save cbscribe/b683e8eb6c994d543c1c5c652ea8912b to your computer and use it in GitHub Desktop.
Save cbscribe/b683e8eb6c994d543c1c5c652ea8912b to your computer and use it in GitHub Desktop.
Arduino worksheet 2, question 3
void setup()
{
pinMode(12, OUTPUT);
pinMode(2, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}
int led = LOW;
int button_right;
int last_button_right;
int button_left;
int last_button_left;
void loop()
{
last_button_right = button_right;
button_right = digitalRead(2);
if (button_right == LOW && last_button_right == HIGH)
{
led = LOW;
}
last_button_left = button_left;
button_left = digitalRead(4);
if (button_left == LOW && last_button_left == HIGH)
{
led = HIGH;
}
digitalWrite(12, led);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment