//referensi: https://mechatrofice.com/arduino/arduino-counter-code-circuit-working
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define buttonCounter 7
#define ledPin 12
int counterState=0;
int counterPresState=0;
int counterValue=0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonCounter, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("Counter UP");
lcd.setCursor(6,1);
lcd.print("00");
}
void loop() {
//cek kondisi buttonCounter (ditekan/tidak)
counterState = digitalRead(buttonCounter);
//seleksi kondisi counterState
if(counterState==LOW && counterPresState==0){
counterValue++;
lcd.setCursor(6,1);
if(counterValue<10){
lcd.print("0");
}
lcd.print(counterValue);
delay(500);
digitalWrite(buttonCounter, HIGH);
counterPresState=1;
}else if(counterState==HIGH){
//Serial.println("Dilepas");
counterPresState=0;
}
}