Skip to content

Instantly share code, notes, and snippets.

@vixtory09678
Created January 15, 2023 21:05
Show Gist options
  • Save vixtory09678/63980a51c933a7fe1a1e1631f871dd74 to your computer and use it in GitHub Desktop.
Save vixtory09678/63980a51c933a7fe1a1e1631f871dd74 to your computer and use it in GitHub Desktop.
#include "Arduino.h"
#define BUTTON_GPIO 33
#define DEBOUNCE_DELAY 100
unsigned long lastDebounceTime = 0;
bool buttonState = HIGH;
void setup() {
pinMode(BUTTON_GPIO, INPUT_PULLUP);
Serial.begin(115200);
}
int count = 0;
void loop() {
int reading = digitalRead(BUTTON_GPIO);
if (!reading) {
if (buttonState == HIGH && ((millis() - lastDebounceTime) > DEBOUNCE_DELAY)) {
buttonState = LOW;
lastDebounceTime = millis();
count += 1;
Serial.printf("click %d\n", count);
}
} else {
buttonState = HIGH;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment