#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2);
const int button1 = A0;
const int button2 = A1;
const int relay1 = 2;
const int relay2 = 3;
int masuk = 0;
int keluar= 0;
int total = 0;
void setup() {
// put your setup code here, to run once:
pinMode(button1, INPUT_PULLUP);pinMode(button2, INPUT_PULLUP);
pinMode(relay1,OUTPUT);pinMode(relay2, OUTPUT);
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(0,1);
lcd.print("PENGUNJUNG: ");
delay(200);
}
void loop()
// put your main code here, to run repeatedly:
{
masuk = digitalRead(button1);
keluar = digitalRead(button2);
if(masuk == LOW){
total++;
delay(500);
}
if(keluar == LOW){
total--;
delay(500);
}
if(total<=0){
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
lcd.setCursor(0,1);
lcd.print("PENGUNJUNG: ");
}
else if (total>0 && total<10){
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
lcd.setCursor(0,1);
lcd.print("PENGUNJUNG: ");
lcd.setCursor(12,1);
lcd.print(total);
lcd.setCursor(13,1);
lcd.print(" ");
}
else{
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
lcd.setCursor(0,1);
lcd.print("PENGUNJUNG: ");
lcd.setCursor(12,1);
lcd.print(total);
}
}