Skip to content

Instantly share code, notes, and snippets.

@Rulexec
Created April 21, 2021 19:36
Show Gist options
  • Save Rulexec/5bd642594b7d50865ea5031e403a75b4 to your computer and use it in GitHub Desktop.
Save Rulexec/5bd642594b7d50865ea5031e403a75b4 to your computer and use it in GitHub Desktop.
#define PIN_PEDAL_ANALOG A0
#define PIN_LED 8
#define MIN_LEVEL 590
#define MAX_LEVEL 620
bool pedalEnabled = false;
void setup() {
pinMode(PIN_LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
int value = analogRead(PIN_PEDAL_ANALOG);
bool enabled;
if (value >= MAX_LEVEL) {
enabled = true;
} else if (value < MIN_LEVEL) {
enabled = false;
} else {
delay(10);
return;
}
if (enabled == pedalEnabled) {
delay(10);
return;
}
if (enabled) {
Serial.println("#ON#");
} else {
Serial.println("#OFF#");
}
pedalEnabled = enabled;
digitalWrite(PIN_LED, enabled ? HIGH : LOW);
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment