#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
String input;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
for (int i=2;i<=7;i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Select lamp: 1-6; 9: ALL ON; 0: ALL OFF");
while (!Serial.available()){}
input = Serial.readString();
int nomor = input.toInt();
if (nomor==0) {
for (int i = 2; i<=7;i++){
digitalWrite(i, LOW);
}
lcd.setCursor(0,0);
lcd.print("SEMUA LAMPU MATI..");
}
else if (nomor==9){
for (int i = 2; i<=7;i++){
digitalWrite(i,HIGH);
}
lcd.setCursor(0,0);
lcd.print("SEMUA LAMPU HIDUP.");
}
else {
for (int i = 2; i<=7;i++){
digitalWrite(i, i==(nomor+1)?HIGH:LOW);
}
lcd.setCursor(0,0);
if (nomor <=6) {
lcd.print("Lampu " + String(nomor) + " hidup....");
}
else {
lcd.print("TAK ADA NOMOR ITU!");
}
}
delay(1000);
}