#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int led[3] = {10, 11, 12};
int green = 10; // Grüne LED
int yellow = 11; // Gelbe LED
int red = 12; // Rote LED
int poti = A1; // Potentiometer
int poti_wert; // Potentiometer-Wert
int led_index;
void setup() {
// put your setup code here, to run once:
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
pinMode(poti, INPUT);
lcd.init();
lcd.backlight();
//Serial.begin(9600); // =Baudrate, bits per second
}
void loop() {
poti_wert = analogRead(poti);
//Serial.print(poti_wert);
led_index = map(poti_wert, 0, 1023, 0, 2);
for (int i = 0; i < 3; i++) {
digitalWrite(led[i], LOW); // LED wird ausgeschaltet abhängig vom Index
}
digitalWrite(led[led_index], HIGH);
if (led_index == 0) { // Grün
lcd.setCursor(0, 0);
lcd.print("Alles im gruenen");
lcd.setCursor(0, 1);
lcd.print(" Bereich ");
//Serial.println(" Alles im grünen Bereich");
} else if (led_index == 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Achtung");
//Serial.println(" Achtung, Wert im gelben Bereich");
} else if (led_index == 2) {
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("!!!");
lcd.setCursor(0, 1);
lcd.print("Bereich kritisch");
//Serial.println(" Warnung, kritischen Bereich erreicht!");
}
delay(500);
}