Last active
January 8, 2018 22:45
-
-
Save kachurovskiy/c08671a9b4dd14940f1b23d102d3f96b to your computer and use it in GitHub Desktop.
Double-clap to toggle the light. https://youtu.be/0-Un6Gu4Ah0
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
bool isOn = false; | |
void setup() { | |
pinMode(2, OUTPUT); | |
digitalWrite(2, isOn ? HIGH : LOW); | |
} | |
int th = 40; | |
void toggle() { | |
if (isOn) { | |
isOn = false; | |
digitalWrite(2, LOW); | |
} else { | |
isOn = true; | |
digitalWrite(2, HIGH); | |
} | |
} | |
void loop() { | |
if (analogRead(A2) > th) { | |
delay(200); | |
if (analogRead(A2) > th) { | |
delay(1000); | |
return; | |
} | |
for (int i = 0; i < 2000; i++) { | |
if (analogRead(A2) > th) { | |
toggle(); | |
delay(1000); | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment