Skip to content

Instantly share code, notes, and snippets.

@joneskoo
Created February 28, 2016 16:33
Show Gist options
  • Save joneskoo/c288ca30a25c67dd892f to your computer and use it in GitHub Desktop.
Save joneskoo/c288ca30a25c67dd892f to your computer and use it in GitHub Desktop.
Door bell glitch removal bugfix
void loop() {
int oldButtonState = digitalRead(buttonPin);
// Wait for button to be pressed
while (1) {
int buttonState = digitalRead(buttonPin);
// Button state changed
if (buttonState != oldButtonState) {
// glitch removal - wait GLITCH_US and if button state still
// changed, proceed
delayMicroseconds(GLITCH_US);
+ buttonState = digitalRead(buttonPin);
if (buttonState != oldButtonState) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment