#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Alamat I2C dan ukuran LCD
const int button1Pin = A0; // Pin untuk push button 1
const int button2Pin = A1; // Pin untuk push button 2
int counter = 0; // Variabel untuk menyimpan nilai
int button1State = HIGH; // Status push button 1
int button2State = HIGH;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(4, 0);
lcd.print("WELCOME");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("Frekuensi Meter");
lcd.setCursor(0, 1);
lcd.print("Nilai: ");
lcd.setCursor(8, 1);
lcd.print(counter);
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(button1Pin) == LOW) {
delay(250); // Debouncing delay
counter++;
if (counter>500)counter=500;
displayCounter();
}
if (digitalRead(button2Pin) == LOW) {
delay(200); // Debouncing delay
counter--;
if (counter<0) counter=0;
displayCounter();
} }
void displayCounter() {
lcd.setCursor(8, 1);
lcd.print(" "); // Clear previous value
lcd.setCursor(8, 1);
lcd.print(counter);
}