#include <LiquidCrystal.h> const int butpin = 8; int buttonState = HIGH; int lastbuttonState = HIGH; unsigned long lastDebounceTime = 0; unsigned long debounceDelay = 50; int butVal; int pressCounter = 0; const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup(){ pinMode(8, INPUT); lcd.begin(16, 2); Serial.begin(9600); } void loop(){ butVal = digitalRead(butpin); if(butVal != lastbuttonState){ lastDebounceTime = millis(); } if((millis() - lastDebounceTime) > debounceDelay){ if(butVal != buttonState){ buttonState = butVal; if(buttonState == HIGH){ pressCounter++; } } lcd.setCursor(0, 0); lcd.print("Steps: "); lcd.print(pressCounter); } lastbuttonState = butVal; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter