#include <LiquidCrystal_I2C.h>
const int buttonPin1 = 2 , buttonPin2 = 3 ;
int button1_State = 0 , button2_State = 0 ;
int count_value = 0 ;
int prestate = 0 ;
LiquidCrystal_I2C LCD ( 0x27 , 16 , 2 ) ;
int led1 = 13 , led2 = 12 ;
void setup ( ) {
// inisialisasi pin tombol sebagai input:
pinMode ( buttonPin1 , INPUT ) ;
pinMode ( buttonPin2 , INPUT ) ;
pinMode(led1 , OUTPUT);
pinMode(led2 , OUTPUT);
LCD . init ( ) ;
LCD . backlight ( ) ;
LCD . setCursor ( 4 , 0 ) ;
LCD . print ( "PENGUNJUNG" ) ;
LCD . setCursor ( 2 , 1 ) ;
LCD . print ( count_value ) ;
}
void loop ( ) {
// membaca status nilai tombol tekan:
button1_State = digitalRead ( buttonPin1 ) ;
button2_State = digitalRead ( buttonPin2 ) ;
// periksa apakah tombol ditekan. Jika ya, buttonState adalah HIGH:
if ( button1_State == HIGH && prestate == 0 ) {
count_value ++ ;
LCD . setCursor ( 0 , 1 ) ;
LCD . print ( ">" ) ;
LCD . print ( count_value ) ;
LCD . print ( " " ) ;
prestate = 1 ;
delay(300);
}
//kurangi yang lain :
if ( button2_State == HIGH && prestate == 0 ) {
count_value -- ;
LCD . setCursor ( 0 , 1 ) ;
LCD . print ( "<" ) ;
LCD . print ( count_value ) ;
LCD . print ( " " ) ;
prestate = 1 ;
delay(300);
}
else if ( button1_State == LOW && button2_State == LOW ) {
prestate = 0 ;
}
if (count_value >= 1) {
digitalWrite(led1, HIGH );
}
else {
digitalWrite(led1, LOW);
}
if (count_value >= 10) {
digitalWrite(led2, HIGH);
}
else {
digitalWrite(led2, LOW);
}
}