Created
April 21, 2021 19:36
-
-
Save Rulexec/5bd642594b7d50865ea5031e403a75b4 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 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