const int buttonPin = 2;
int eventCounter = 0;
bool stableButtonState = HIGH;
bool lastReading = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
bool reading = digitalRead(buttonPin);
if (reading != lastReading) {
lastDebounceTime = currentMillis;
lastReading = reading;
}
if (currentMillis - lastDebounceTime > debounceDelay) {
if (reading != stableButtonState) {
stableButtonState = reading;
if (stableButtonState == LOW) {
eventCounter++;
unsigned long seconds = currentMillis / 1000;
Serial.print("Zdarzenie ");
Serial.print(eventCounter);
Serial.print(" o czasie ");
Serial.print(seconds);
Serial.println(" sekund.");
}
}
}
}