Professional Documents
Culture Documents
Counter LCD Push Button - Code1.ino
Counter LCD Push Button - Code1.ino
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
Serial.begin(9600);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Please Select:");
lcd.setCursor(2,1);
lcd.print(buttonPushCounter);
void loop()
checkUp();
checkDown();
if( bPress){
bPress = false;
lcd.setCursor(2,1);
lcd.print(" ");
lcd.setCursor(2,1);
lcd.print(buttonPushCounter);
void checkUp()
up_buttonState = digitalRead(Up_buttonPin);
if (up_buttonState != up_lastButtonState) {
if (up_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
delay(50);
// save the current state as the last state, for next time through the loop
up_lastButtonState = up_buttonState;
void checkDown()
down_buttonState = digitalRead(Down_buttonPin);
if (down_buttonState != down_lastButtonState) {
if (down_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter--;
Serial.println("on");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
delay(50);
// save the current state as the last state, for next time through the loop
down_lastButtonState = down_buttonState;