#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Servo servo1;
Servo servo2;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int irProximity1 = 2; // Sensor Infrared Proximity 1
const int irProximity2 = 3; // Sensor Infrared Proximity 2
const int buzzerPin = 4; // Active Buzzer
int halanganCount1 = 0;
bool countdownStarted = false;
unsigned long countdownStartTime = 0;
const int countdownDuration = 10000; // 10 seconds
void setup() {
servo1.attach(5); // Servo 1
servo2.attach(6); // Servo 2
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Selamat Datang");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Masukkan Coin");
}
void loop() {
if (digitalRead(irProximity1) == LOW) {
halanganCount1++;
if (halanganCount1 == 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Countdown: 10s");
countdownStartTime = millis();
countdownStarted = true;
} else if (halanganCount1 == 2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Silahkan Pilih");
countdownStarted = false;
}
}
if (countdownStarted) {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - countdownStartTime;
int remainingTime = (countdownDuration - elapsedTime) / 1000;
if (remainingTime >= 0) {
lcd.setCursor(0, 1);
lcd.print("Countdown: " + String(remainingTime) + "s");
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Waktu Habis");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Masukkan Coin");
halanganCount1 = 0;
countdownStarted = false;
}
}
}