#include <LiquidCrystal_I2C.h>
int pinLed1 = 13;
int pinled2 = 14;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
//Pin yg akan digunakan (led)
pinMode(pinLed1, OUTPUT);
pinMode(pinled2, OUTPUT);
}
void loop() {
lcd.setCursor(0, 0);{
lcd.print("PRAKTEK ESP32 ");
}
// Loop yang dimulai dari nilai pinLed1 dan berlanjut hingga nilai i mencapai pinled2,
// menambah nilai i sebesar 1 pada setiap iterasi.
for (int i = pinLed1; i <= pinled2; i++) {
digitalWrite(i, HIGH);
lcd.setCursor(0, 1);
lcd.print("LED ");
if(i == pinLed1){
lcd.print("merah");
lcd.println(" on");
}
else if (i == pinled2){
lcd.print("biru");
lcd.println(" on");
}
lcd.setCursor(0, 2);
lcd.print("LED ");
if(i == pinLed1){
lcd.print("biru");
lcd.println(" off");
}
else if (i == pinled2){
lcd.print("merah");
lcd.println(" off");
}
delay(1000);
digitalWrite(i, LOW);
}
}