Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Last active July 6, 2020 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/743e027480bf6242785807943669e768 to your computer and use it in GitHub Desktop.
Save JeffersGlass/743e027480bf6242785807943669e768 to your computer and use it in GitHub Desktop.
const int buttonPin = 2;
const int ledPin = 9;
volatile int count = 0;
volatile long lastIncrement = 1;
const long minButtonPressTime = 100;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(38400);
attachInterrupt(digitalPinToInterrupt(2), setState, FALLING);
}
void loop() {
Serial.println(count);
delay(1000);
}
void setState(){
if (millis() > lastIncrement + minButtonPressTime){
lastIncrement = millis();
count++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment