Skip to content

Instantly share code, notes, and snippets.

@kachurovskiy
Last active January 8, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kachurovskiy/c08671a9b4dd14940f1b23d102d3f96b to your computer and use it in GitHub Desktop.
Save kachurovskiy/c08671a9b4dd14940f1b23d102d3f96b to your computer and use it in GitHub Desktop.
Double-clap to toggle the light. https://youtu.be/0-Un6Gu4Ah0
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