I am a newbie with arduino. I am trying to have a counter with 3 buttons. Each Button when pressed will increase the number of counts. The counter should still count if button 2 is pressed while button 1 has not been released, and button 3 should also be able to increase the counter even if button 2 and button 1 are still pressed.
My code below counts if only one button is pressed at a time.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int pbutton1 = 2;
int pbutton2 = 3;
int pbutton3 = 4;
int count = 0;
void setup() {
lcd.begin(16, 2);
pinMode (pbutton1, INPUT);
pinMode (pbutton2, INPUT);
pinMode (pbutton3, INPUT);
lcd.print("My Counter");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print("Total ");
if (digitalRead(pbutton1) == HIGH) {
lcd.print(count++);
while (digitalRead(pbutton1) == HIGH); //monitor button to avoid continous count
}
if (digitalRead(pbutton2) == HIGH) {
lcd.print(count++);
while (digitalRead(pbutton2) == HIGH); //monitor button to avoid continous count
}
if (digitalRead(pbutton3) == HIGH) {
lcd.print(count++);
while (digitalRead(pbutton3) == HIGH); //monitor button to avoid continous count
}
}