//referensi: https://mechatrofice.com/arduino/arduino-counter-code-circuit-working
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define buttonJamz 7
#define button Menitz 4
#define ledPin 12
int JamzState=0;
int JamzPresState=0;
int JamzValue=0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonJamz, INPUT_PULLUP);
pinMode(buttonMenitz, 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(buttonJamz);
//seleksi kondisi counterState
if(counterState==LOW && counterPresState==0){
if(counterValue<24){
counterValue++;
} else {
counterValue=0;
}
lcd.setCursor(6,1);
if(counterValue<10){
lcd.print("0");
}
lcd.print(counterValue);
delay(500);
digitalWrite(buttonJamz, HIGH);
counterPresState=1;
}else if(counterState==HIGH){
//Serial.println("Dilepas");
counterPresState=0;
}
}
void cekAlarmJam(){
//cek kondisi buttonCounter (ditekan/tidak)
counterState = digitalRead(buttonJamz);
//seleksi kondisi counterState
if(counterState==LOW && counterPresState==0){
if(counterValue<24){
counterValue++;
} else {
counterValue=0;
}
lcd.setCursor(6,1);
if(counterValue<10){
lcd.print("0");
}
lcd.print(counterValue);
delay(500);
digitalWrite(buttonMenitz, HIGH);
counterPresState=1;
}else if(counterState==HIGH){
//Serial.println("Dilepas");
counterPresState=0;
}
}