Created
November 10, 2020 17:21
-
-
Save cbscribe/b683e8eb6c994d543c1c5c652ea8912b to your computer and use it in GitHub Desktop.
Arduino worksheet 2, question 3
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); | |
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