#include <LiquidCrystal_I2C.h>
#define TOMBOL1_PIN 32
#define TOMBOL2_PIN 33
#define TOMBOL3_PIN 25
#define RELAY1_PIN 26
#define RELAY2_PIN 27
LiquidCrystal_I2C lcd(0x27,16,2);
int status_tombol1, status_tombol2, status_tombol3;
void setup() {
// put your setup code here, to run once:
pinMode(TOMBOL1_PIN, INPUT_PULLUP);
pinMode(TOMBOL2_PIN, INPUT_PULLUP);
pinMode(TOMBOL3_PIN, INPUT_PULLUP);
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
digitalWrite(RELAY1_PIN, HIGH);
digitalWrite(RELAY2_PIN, HIGH);
// digitalWrite(RELAY1_PIN, LOW);
// digitalWrite(RELAY2_PIN, LOW);
// Serial.begin(115200);
// Serial.println("Hello, ESP32!");
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
// Print a message on both lines of the LCD.
lcd.setCursor(0,0); //Set cursor to character 2 on line 0
lcd.print("Tes Button&Relay");
lcd.setCursor(0,1); //Move cursor to character 2 on line 1
lcd.print(" Tekan Tombol ");
}
void loop() {
// put your main code here, to run repeatedly:
status_tombol1 = digitalRead(TOMBOL1_PIN);
status_tombol2 = digitalRead(TOMBOL2_PIN);
status_tombol3 = digitalRead(TOMBOL3_PIN);
if(status_tombol1 == LOW) {
delay(20);
status_tombol1 = digitalRead(TOMBOL1_PIN);
if(status_tombol1 == LOW) {
// lcd.clear();
lcd.setCursor(0,0);
lcd.print("> Tombol 1 Aktif");
digitalWrite(RELAY1_PIN, LOW);
// digitalWrite(RELAY1_PIN, HIGH);
lcd.setCursor(0,1);
lcd.print("> Relay 1 Aktif ");
}
}
if(status_tombol2 == LOW) {
delay(20);
status_tombol2 = digitalRead(TOMBOL2_PIN);
if(status_tombol2 == LOW) {
// lcd.clear();
lcd.setCursor(0,0);
lcd.print("> Tombol 2 Aktif");
digitalWrite(RELAY2_PIN, LOW);
// digitalWrite(RELAY2_PIN, HIGH);
lcd.setCursor(0,1);
lcd.print("> Relay 2 Aktif ");
}
}
if(status_tombol3 == LOW) {
delay(20);
status_tombol3 = digitalRead(TOMBOL3_PIN);
if(status_tombol3 == LOW) {
// lcd.clear();
lcd.setCursor(0,0);
lcd.print("> Tombol 3 Aktif");
digitalWrite(RELAY1_PIN, HIGH);
digitalWrite(RELAY2_PIN, HIGH);
// digitalWrite(RELAY1_PIN, LOW);
// digitalWrite(RELAY2_PIN, LOW);
lcd.setCursor(0,1);
lcd.print("> Relay Off ");
}
}
delay(10); // this speeds up the simulation
}