#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define TombolPilih 11
#define TombolOn 10
#define TombolOff 7
#define Tekan LOW
#define waktu 100
#define Awal 3000
#define masuk 2000
#define BT 300
int relay1 = 9;
int relay2 = 8;
//------------------------------
LiquidCrystal_I2C lcd (0x27,16,2);
byte Menara1[] = {
B00000,
B01010,
B11111,
B01110,
B01110,
B01110,
B11111,
B00000
};
byte Menara2[] = {
B00000,
B01010,
B11111,
B01110,
B01110,
B01110,
B11111,
B00000
};
void setup(){
lcd.init();
lcd.backlight();
lcd.begin(16,2);
pinMode(TombolPilih, INPUT_PULLUP);
pinMode(TombolOn, INPUT_PULLUP);
pinMode(TombolOff, INPUT_PULLUP);
//-------Tampilan Menu Awal--------//
lcd.createChar(0, Menara1);
lcd.createChar(8, Menara2);
lcd.setCursor(0,0);
lcd.write(byte(0));
lcd.setCursor(15,0);
lcd.write(byte(8));
lcd.setCursor(6,0);
lcd.print("YOOP");
lcd.setCursor(3,1);
lcd.print("SIMULATION");
delay(masuk);
}
void loop(){
delay(waktu);
lcd.clear();
// set masuk tampilan
setRelay1:
if (digitalRead(TombolOn) == Tekan ){
delay(BT);
digitalWrite(relay1, HIGH);
lcd.setCursor(9,0);
lcd.print("ON");
}
if(digitalRead(TombolOff) == Tekan ){
delay(BT);
digitalWrite(relay1, LOW);
lcd.setCursor(9,0);
lcd.print("OF");
}else if (digitalRead(TombolPilih) == Tekan ){
while (digitalRead(TombolPilih) == Tekan ){}
goto setRelay2;
}
lcd.setCursor(0,0);
lcd.print(">Relay 1 ");
lcd.setCursor(0,1);
lcd.print(" Relay 2");
goto setRelay1;
//-----------------------------------------------------
setRelay2:
if (digitalRead(TombolOn) == Tekan ){
delay(BT);
digitalWrite(relay2, HIGH);
lcd.setCursor(9,1);
lcd.print("ON");
}
if(digitalRead(TombolOff) == Tekan ){
delay(BT);
digitalWrite(relay2, LOW);
lcd.setCursor(9,1);
lcd.print("OF");
}else if (digitalRead(TombolPilih) == Tekan ){
while (digitalRead(TombolPilih) == Tekan ){}
goto setRelay1;
}
lcd.setCursor(0,0);
lcd.print(" Relay 1 ");
lcd.setCursor(0,1);
lcd.print(">Relay 2");
goto setRelay2;
//-----------------------------------------------------
}
// #include <LiquidCrystal_I2C.h>
// #include <Wire.h>
// const int BPin =10;
// #define BOK 11
// int BPState = 0;
// int BOState = 0;
// const int relay1 = 8;
// const int relay2 = 9;
// bool aktif =false;
// LiquidCrystal_I2C lcd (0x27,16,2);
// void setup(){
// pinMode(BPin, INPUT_PULLUP);
// pinMode(BOK, INPUT);
// pinMode(relay1, OUTPUT);
// pinMode(relay2, OUTPUT);
// }
// void loop(){
// BPState = digitalRead(BPin);
// BOState = digitalRead(BOK);
// if (BPState == LOW && aktif){
// digitalWrite(relay1, HIGH);
// aktif = true;
// }
// if (BPState == HIGH && aktif){
// digitalWrite(relay1, LOW);
// aktif = false;
// }
// }
// const int buttonPin1 = 11; // Pin untuk tombol
// const int buttonPin2 = 10;
// const int ledPin1 = 8; // Pin untuk LED
// const int ledPin2 = 9;
// int buttonState1 = 0;
// int lastButtonState1 = 0;
// bool ledStatus1 = false;
// int buttonState2 = 0;
// int lastButtonState2 = 0;
// bool ledStatus2 = false;
// void setup() {
// pinMode(buttonPin1, INPUT_PULLUP);
// pinMode(buttonPin2, INPUT_PULLUP);
// pinMode(ledPin1, OUTPUT);
// digitalWrite(ledPin1, LOW);
// pinMode(ledPin2, OUTPUT);
// digitalWrite(ledPin2, LOW);
// }
// void loop() {
// buttonState1 = digitalRead(buttonPin1);
// buttonState2 = digitalRead(buttonPin2);
// if (buttonState1 != lastButtonState1) {
// if (buttonState1 == LOW) {
// ledStatus1 = !ledStatus1; // Mengubah status LED (ON menjadi OFF atau OFF menjadi ON)
// digitalWrite(ledPin1, ledStatus1);
// }
// delay(50); // Debouncing - mencegah bouncing saat menekan tombol
// } else if (buttonState2 != lastButtonState2) {
// if (buttonState2 == LOW) {
// ledStatus2 = !ledStatus2; // Mengubah status LED (ON menjadi OFF atau OFF menjadi ON)
// digitalWrite(ledPin2, ledStatus2);
// }
// delay(50); // Debouncing - mencegah bouncing saat menekan tombol
// }
// lastButtonState1 = buttonState1;
// lastButtonState2 = buttonState2;
// }