#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int pinSensor = 8;
const int pinReset = 9;
int hitung = 0;
int kondisi1 = 0;
int status1;
void setup()
{
pinMode(pinReset, INPUT);
digitalWrite(pinReset, HIGH);
pinMode(pinSensor, INPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alat Penghitung");
lcd.setCursor(0, 1);
lcd.print("Jumlah Barang ...");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ready ... ");
delay(1000);
}
void loop()
{
hitung = constrain(hitung, 0, 10);
status1 = digitalRead(pinSensor);
if (status1 == HIGH)
{
hitung = hitung;
kondisi1 = 0;
}
else if (status1 == LOW && kondisi1 == 0)
{
hitung += 1;
kondisi1 = 1;
}
else if (status1 == LOW && kondisi1 == 1)
{
hitung = hitung;
kondisi1 = 1;
}
if (digitalRead(pinReset) == LOW)
{
hitung = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("RESET Aktif ...");
delay(1000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Jumlah Barang : ");
lcd.setCursor(0, 1);
lcd.print(hitung);
delay(300);
}