Hey all, I am having a problem with my code and was hoping someone could help shed some light on how to fix it. Below is a code for an arduino push button counter. The concept is that there are 2 buttons, an "add" button and "subtract" button. Every time add is pressed it adds 1 to the count and vice versa when subtract is hit. The code works fine until we hit double digits. Once you subtract from 1 from 10 the LCD displays 90 not 9. Not sure how to fix this, any ideas?
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
int add=8;
int sub=9;
int valadd;
int valsub;
int count=000;
int press;
void setup() {
lcd.begin(16,2);
pinMode(add,INPUT);
pinMode(sub,INPUT);
}
void loop() {
valadd=digitalRead(add);
valsub=digitalRead(sub);
if(valadd==HIGH) {
delay(100);
press=count++;
delay(250);
}
if(valsub==HIGH) {
delay(100);
press=count--;
delay(250);
}
lcd.setCursor(0,0);
lcd.print("Button count");
lcd.setCursor(0,1);
lcd.print(press);
}
Counter.ino (725 Bytes)