// https://wokwi.com/projects/424431180303060993
const byte theButton = 3;
const byte theLED = 6;
# define PRESST LOW
void setup() {
Serial.begin(115200);
Serial.println("\nbounce house\n");
pinMode(theButton, INPUT_PULLUP);
pinMode(theLED, OUTPUT);
}
unsigned long currentMillis;
void loop()
{
currentMillis = millis();
bogusButtonHandler();
}
int counter;
bool buttonPressed;
unsigned long lastPressTime;
void bogusButtonHandler()
{
bool buttonState = digitalRead(theButton) == PRESST;
if (!buttonState) {
buttonPressed = false;
return;
}
if (!buttonPressed && currentMillis - lastPressTime > 100) {
buttonPressed = true;
lastPressTime = currentMillis;
// count and report button press, toggle the LED
counter++;
Serial.print("press number ");
Serial.print(counter);
Serial.println(" detected.");
digitalWrite(theLED, digitalRead(theLED) == HIGH ? LOW : HIGH);
}
}