#include <LiquidCrystal.h>
#define PB1 A0
#define PB2 A1
#define PB3 A2
#define PB4 A3
#define PB5 A4
#define PB6 A5
#define PB7 12
#define PB8 13
const int rs = 11, en = 10, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
bool Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8;
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
pinMode(PB1, INPUT);
pinMode(PB2, INPUT);
pinMode(PB3, INPUT);
pinMode(PB4, INPUT);
pinMode(PB5, INPUT);
pinMode(PB6, INPUT);
pinMode(PB7, INPUT);
pinMode(PB8, INPUT);
}
void loop() {
Button1 = digitalRead(PB1);
Button2 = digitalRead(PB2);
Button3 = digitalRead(PB3);
Button4 = digitalRead(PB4);
Button5 = digitalRead(PB5);
Button6 = digitalRead(PB6);
Button7 = digitalRead(PB7);
Button8 = digitalRead(PB8);
if(Button1==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW &
Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Merah");
}
else if(Button2==HIGH & Button1==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kuning");
}
else if(Button3==HIGH & Button2==LOW & Button1==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hijau");
}
else if(Button4==HIGH & Button2==LOW & Button3==LOW & Button1==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Biru");
}
else if(Button5==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button1==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Merah");
}
else if(Button6==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button1==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Hijau");
}
else if(Button7==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button1==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Biru");
}
else if(Button8==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button1==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Putih");
}
else if(Button1==LOW & Button2==LOW & Button3==LOW & Button5==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Silahkan Tekan");
lcd.setCursor(0, 1);
lcd.print("Salah Satu SW");
}
else{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error");
}
delay(100); // Tambahkan penundaan agar tampilan tidak berubah terlalu cepat
}
Tidak ada komentar:
Posting Komentar