Created
November 15, 2011 11:37
-
-
Save fullmated/1366861 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
#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