Skip to content

Instantly share code, notes, and snippets.

@fullmated
Created November 15, 2011 11:37
Show Gist options
  • Save fullmated/1366861 to your computer and use it in GitHub Desktop.
Save fullmated/1366861 to your computer and use it in GitHub Desktop.
#define LED 13
#define BUTTON 7
int val;
int flag, flag2, sw;
void setup(){
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
sw = flag = flag2 = 0;
}
void loop(){
val = digitalRead(BUTTON);
if(!flag && !flag2 && val == HIGH){
flag = 1;
}else if(flag && flag2 && val == LOW){
flag = 0;
}else if(flag && !flag2 && val == HIGH){
flag2 = 1; sw = sw?0:1;
}else if(!flag && flag2 && val == LOW){
flag2 = 0;
}
if(sw){
digitalWrite(LED, HIGH);
}else{
digitalWrite(LED, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment