// waa waa pedal
unsigned long settledTimerPreset = 1000;
unsigned long settledTimerAccValue;
unsigned long pulseTimerPreset = 500;
unsigned long pulseTimerAccValue;
byte settledOutputPin = 6;
byte pulseOutputPin = 4;
int threshold = 25;
void setup() {
Serial.begin(115200);
pinMode(settledOutputPin, OUTPUT);
pinMode(pulseOutputPin, OUTPUT);
}
void loop() {
bool belowThreshold, settled;
static bool lastSettled;
int potValue = analogRead(A0);
belowThreshold = (potValue < threshold ? true : false);
if (belowThreshold) {
pulseTimerAccValue = millis(); // reset pulse timer
digitalWrite(pulseOutputPin, LOW); // reset rising output
}
else settledTimerAccValue = millis(); // reset settled timer
if (millis() - settledTimerAccValue >= settledTimerPreset) {
digitalWrite(settledOutputPin, HIGH);
settled = true;
}
else {
digitalWrite(settledOutputPin, LOW);
settled = false;
}
if (settled and !lastSettled) {
if (millis() - pulseTimerAccValue < pulseTimerPreset) {
digitalWrite(pulseOutputPin, HIGH);
}
else digitalWrite(pulseOutputPin, LOW);
}
lastSettled = settled;
} // end of loop