Skip to content

Instantly share code, notes, and snippets.

@zach-c-d
Created December 13, 2017 06:36
Show Gist options
  • Save zach-c-d/c7f4f68a261410d6efbb223d0825673a to your computer and use it in GitHub Desktop.
Save zach-c-d/c7f4f68a261410d6efbb223d0825673a to your computer and use it in GitHub Desktop.
int button = 8;
void setup(){
pinMode(button, INPUT);
Serial.begin(9600);
}
unsigned long prevMillis = 0;
unsigned long prevMillisButtonCheck = 0;
unsigned long currentMillis;
boolean buttonCheck = false;
int count; //the number of button presses per interval
void loop(){
currentMillis = millis();
//record if the button is pushed
if(digitalRead(button) == HIGH){
buttonCheck = true;
}
//if 30 milliseconds have passed, and the button is released, and the butotn has been pushed
if(currentMillis - prevMillisButtonCheck >=30 &&
digitalRead(button) == false &&
buttonCheck == true)
{
count++;
buttonCheck = false;
prevMillisButtonCheck = currentMillis;
}
if(currentMillis - prevMillis >= 1000){
Serial.println(count);
count = 0;
prevMillis = currentMillis;
}
}
boolean checkforClick(){
int check = false;
if(digitalRead(button) == HIGH){
check = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment