Skip to content

Instantly share code, notes, and snippets.

@margmarg
Created September 16, 2021 03:59
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 margmarg/7ff0525e790957e7f801e15437d9ab9a to your computer and use it in GitHub Desktop.
Save margmarg/7ff0525e790957e7f801e15437d9ab9a to your computer and use it in GitHub Desktop.
// how many times a button has been pressed since the beginning of time
const int BUTTON_PIN = 3;
int buttonCount = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
if (digitalRead(BUTTON_PIN) == HIGH) {
while (digitalRead(BUTTON_PIN) == HIGH) {
// while it is still high do not change anything
// otherwise when it goes LOW increment buttonCount
}
buttonCount = buttonCount + 1; //buttonCount += 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment