#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int potPin = A0;
const int ledRedPin = 2;
const int ledYellowPin = 3;
const int ledGreenPin = 4;
void setup() {
Serial.begin(115200);
pinMode(ledRedPin, OUTPUT);
pinMode(ledYellowPin, OUTPUT);
pinMode(ledGreenPin, OUTPUT);
lcd.begin(16, 2);
lcd.backlight();
}
void loop() {
int potValue = analogRead(potPin);
Serial.println(potValue);
potValue = analogRead(potPin);
if (potValue >= 0 && potValue <= 341) {
digitalWrite(ledRedPin, HIGH);
digitalWrite(ledYellowPin, LOW);
digitalWrite(ledGreenPin, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("led green on");
lcd.setCursor(0, 1);
lcd.print("Value: ");
lcd.print(potValue);
}
if (potValue >= 342 && potValue <= 682) {
digitalWrite(ledRedPin, LOW);
digitalWrite(ledYellowPin, HIGH);
digitalWrite(ledGreenPin, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("led yellow on");
lcd.setCursor(0, 1);
lcd.print("Value: ");
lcd.print(potValue);
}
if (potValue >= 683 && potValue <= 1023) {
digitalWrite(ledRedPin, LOW);
digitalWrite(ledYellowPin, LOW);
digitalWrite(ledGreenPin, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("led red on");
lcd.setCursor(0, 1);
lcd.print("Value: ");
lcd.print(potValue);
}
// Tunggu sebentar sebelum membaca nilai berikutnya
delay(100);
}