Skip to content

Instantly share code, notes, and snippets.

@naokirin
Created May 24, 2018 13:11
Show Gist options
  • Save naokirin/05f9647f07b252d72830dfc3360f85ec to your computer and use it in GitHub Desktop.
Save naokirin/05f9647f07b252d72830dfc3360f85ec to your computer and use it in GitHub Desktop.
void setup() {
Serial.begin(9600);
pinMode(0, INPUT);
}
bool on = false;
bool keep = false;
void loop() {
int val = analogRead(A0);
if (digitalRead(0) == HIGH) {
keep = true;
}
else {
if (keep) {
on = !on;
}
keep = false;
}
if (on) {
analogWrite(5, val / 4);
analogWrite(9, val / 4);
}
else {
analogWrite(5, 0);
analogWrite(9, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment