#include <Wire.h> //protokol kuminikasi I2C
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
const int lmp1 = 14;
const int lmp2 = 25;
const int lmp3 = 32;
const int a1 = 4;
const int a2 = 2;
const int b1 = 5;
const int b2 = 4;
const int c1 = 2;
const int c2 = 15;
bool status = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
Serial.begin(9600);
Wire.begin();
lcd.init();
lcd.backlight();
//lcd.clear();
lcd.setCursor(6,0);
lcd.print("MARI");
lcd.setCursor(5,1);
lcd.print("BERMAIN");
delay(2000);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("PERMAINAN");
lcd.setCursor(4,1);
lcd.print("DIMULAI");
delay(1000);
lcd.clear();
//Definisi out ke LED
pinMode(lmp1,OUTPUT);
pinMode(lmp2,OUTPUT);
pinMode(lmp3,OUTPUT);
//Definisi input dari anak
pinMode(a1,INPUT);
pinMode(a2,HIGH);
pinMode(b1,INPUT);
pinMode(b2,HIGH);
pinMode(c1,INPUT);
pinMode(c2,INPUT);
}
//ada sesuatu
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - lastDebounceTime > debounceDelay) {
if(digitalRead(a1) == HIGH){
if(status == LOW){
digitalWrite(lmp1, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GAGAL");
lcd.setCursor(0,1);
lcd.print("LEVEL 1");
Serial.println("on");
status = HIGH;
delay(1000);
}} else {
if(status == LOW){
digitalWrite(lmp1, LOW);
lcd.clear();
Serial.println("off");
status = LOW;
}
lastDebounceTime = currentMillis;
}
if(digitalRead(b1) == HIGH){
if(status == LOW){
digitalWrite(lmp2, HIGH);
lcd.clear();
lcd.setCursor(0,2);
lcd.print("GAGAL");
lcd.setCursor(0,3);
lcd.print("LEVEL 2");
Serial.println("on");
status = HIGH;
delay(1000);
}} else {
if(status == HIGH){
digitalWrite(lmp2, LOW);
lcd.clear();
Serial.println("off");
status = LOW;
}
lastDebounceTime = currentMillis;
}
if(digitalRead(c2) == HIGH){
if(status == LOW){
digitalWrite(lmp3, HIGH);
lcd.clear();
lcd.setCursor(0,4);
lcd.print("GAGAL");
lcd.setCursor(0,5);
lcd.print("LEVEL 3");
Serial.println("on");
status = HIGH;
delay(1000);
}} else {
if(status == HIGH){
digitalWrite(lmp3, LOW);
lcd.clear();
Serial.println("off");
status = LOW;
}
lastDebounceTime = currentMillis;
}
}
// delay(1000); // this speeds up the simulation
}