#include<LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int kendaraan = 0;
void setup() {
pinMode(5, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("MENGHITUNG ");
lcd.setCursor(0,1);
lcd.print("JUMLAH KENDARAAN");
delay(2000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(5)==LOW){
lcd.setCursor(0,0);
lcd.print("JUMLAH KENDARAAN");
lcd.setCursor(0,1);
kendaraan=kendaraan+1;
lcd.print(kendaraan);
delay(500);
}
if(digitalRead(4)==LOW){
lcd.setCursor(0,0);
lcd.print("JUMLAH KENDARAAN");
lcd.setCursor(0,1);
kendaraan=kendaraan-1;
lcd.print(kendaraan);
delay(500);
}
if(kendaraan < 0){
kendaraan = 0;
lcd.setCursor(0,0);
lcd.clear();
lcd.print("kesalahan");
delay(1000);
}
}