Created
January 20, 2016 17:22
-
-
Save zach-c-d/90573e6d2c955ef3b57e 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; // port of LED | |
const int Button = 7; // port of button | |
int val = 0; // state of the button | |
int state = 0; //0=LED off // 1 =LED on | |
void setup() { | |
pinMode(LED, OUTPUT); //LED(port 13) is output | |
pinMode(Button, INPUT); //Button(port 7) is input | |
} | |
void loop() { | |
val = digitalRead(Button); //val reads and stores the | |
//state of button | |
// check whether button has been pressed on | |
if (val ==HIGH){ | |
state = 1 - state; | |
} | |
if (state == 1) { | |
digitalWrite(LED, HIGH); //turns LED(port 13) on | |
} else { | |
digitalWrite(LED, LOW); //if val evals not HIGH, | |
//turn off port 13 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment