#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int counter;
const int button_1 = 6;
const int button_2 = 7;
const int button_3 = 8;
const int button_4 = 9;
void setup() {
randomSeed(analogRead(A0));
counter = random(100);
lcd.begin(16, 2);
lcd.print("Count: ");
lcd.setCursor(7, 0);
// lcd.print(counter);
Serial.begin(9600);
pinMode(button_1, INPUT_PULLUP);
pinMode(button_2, INPUT_PULLUP);
pinMode(button_3, INPUT_PULLUP);
pinMode(button_4, INPUT_PULLUP);
}
void loop() {
if (digitalRead(button_1) == LOW) {
counter++;
lcd.setCursor(7, 0);
lcd.print(counter);
delay(200); // Debounce delay
}
if (digitalRead(button_2) == LOW) {
counter--;
lcd.setCursor(7, 0);
lcd.print(counter);
delay(200); // Debounce delay
}
if (digitalRead(button_3) == LOW) {
counter = 5;
lcd.setCursor(7, 0);
Serial.print(4);
delay(200); // Debounce delay
}
if (digitalRead(button_4) == LOW) {
counter = 90;
lcd.setCursor(7, 0);
lcd.print(counter);
delay(200); // Debounce delay
}
// Update the counter value without clearing the entire display
delay(100); // Adjust the delay as needed
}