Skip to content

Instantly share code, notes, and snippets.

@systemsoverload
Created January 27, 2015 05:20
Show Gist options
  • Save systemsoverload/cb9600943713dbfe8103 to your computer and use it in GitHub Desktop.
Save systemsoverload/cb9600943713dbfe8103 to your computer and use it in GitHub Desktop.
Simple program to count button presses and display them on a 16x2 LCD screen with TeensyDuino libraries
#include <Bounce.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int buttonPin = 23;
Bounce pushbutton = Bounce(buttonPin, 10); // 10 ms debounce
byte previousState = HIGH;
unsigned int count = 0;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print("Button Presses:");
}
void loop() {
if (pushbutton.update()) {
if (pushbutton.fallingEdge()) {
count = count + 1;
}
} else {
lcd.setCursor(0, 1);
lcd.print(count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment