I got around implementing soft debounce and figured I could post the code, maybe others will find it useful, maybe others will be able to tell me if I did anything wrong. It works very nicely as far as I can see.
int statusLED = 13;
int flashLED = 11;
int actionBtn = 12;
int btnVal = 0;
int softVal = 0;
int bounceTime = 0;
int lastBtnVal = HIGH;
void setup () {
pinMode(statusLED, OUTPUT);
digitalWrite(statusLED, HIGH);
pinMode(flashLED, OUTPUT);
pinMode(actionBtn, INPUT);
Serial.begin(9600); // connect to the serial port
Serial.println("Initialized");
}
void loop() {
btnVal = digitalRead(actionBtn);
if (btnVal == LOW && lastBtnVal == HIGH && bounceTime != -1) {
lastBtnVal = LOW;
Serial.println("Going low");
}
if (bounceTime == -1 && btnVal == HIGH) {
bounceTime = 0;
}
if (btnVal == LOW && lastBtnVal == LOW) {
bounceTime++;
if (bounceTime >= 50) {
bounceTime = -1;
btnVal = HIGH;
Serial.println("Action button debounced!");
}
}
if (btnVal == HIGH && lastBtnVal == LOW) {
softVal = !softVal;
lastBtnVal = HIGH;
Serial.print("Going high with softVal to: ");
Serial.println(softVal);
}
digitalWrite(flashLED, softVal);
}