Created
January 20, 2016 17:22
-
-
Save zach-c-d/c0b934bb3fbcf67ab460 to your computer and use it in GitHub Desktop.
This file contains 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
const int LED = 13; //LED is in port 13 | |
const int BUTTON = 7; //BUTTON is in port 7 | |
int val = 0; //state of the button | |
int old_val = 0; //previous state of button | |
int state = 0; // 0 = LED off // 1 = LED on | |
void setup(){ | |
pinMode(LED, OUTPUT); //port 13 is set to output; | |
pinMode(BUTTON, INPUT); //port 7 is set to input | |
} | |
void loop(){ | |
val = digitalRead(BUTTON); // value of val is the state of button | |
//check if a transition has happened | |
//if there was, | |
if ((val == HIGH) && (old_val == LOW)){ | |
state = 1 - state; | |
} | |
old_val = val; //set most recent val to old_val | |
if (state ==1){ | |
digitalWrite(LED, HIGH); //turn port 13 to high | |
}else{ | |
digitalWrite(LED, LOW); //if state is not 1, port 13 to low | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment