// waa waa pedal
unsigned long settledTimerPreset = 1000;
unsigned long settledTimerAccValue;
unsigned long risingPulseTimerPreset = 500;
unsigned long risingPulseTimerAccValue;
byte settledDownDO = 6;
byte risingPulseDO = 4;
// define switch/case states
enum : byte { belowAndTiming, belowAndDone, aboveXstn, aboveAndTiming, aboveAndDone} pedalState;
int threshold = 256;
bool risingXstn;
bool risingXstnLast;
void setup() {
pinMode(settledDownDO, OUTPUT);
pinMode(risingPulseDO, OUTPUT);
}
void loop() {
static bool belowThreshold;
int potValue = analogRead(A0);
belowThreshold = (potValue <= threshold ? true : false);
bool aboveThreshold = !belowThreshold;
if (belowThreshold) {
risingPulseTimerAccValue = millis(); // reset rising timer
digitalWrite(risingPulseDO, LOW);
// digitalWrite(settledDownDO, HIGH);
risingXstn = false;
}
if (millis() - settledTimerAccValue >= settledTimerPreset) {
pedalState = belowAndDone;
}
else pedalState = belowAndTiming;
if(pedalState==belowAndDone)digitalWrite(settledDownDO, HIGH);
if(pedalState==belowAndTiming )digitalWrite(settledDownDO,LOW);
if (aboveThreshold) {
settledTimerAccValue = millis(); // reset settled timer
digitalWrite(settledDownDO, LOW);
risingXstn=true;
}
} // end of loop