#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
{ '1', '2', '3'},
{ '4', '5', '6'},
{ '7', '8', '9'},
{ '*', '0', '#'}
};
int r1=7, r2=6, r3=5, r4=4, c1=3, c2=2, c3=8; //Variables for pins
uint8_t colPins[COLS] = { c1, c2, c3 }; // Pins connected to C1, C2, C3
uint8_t rowPins[ROWS] = { r1, r2, r3, r4 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputString;
int inputInt;
void setup() {
// Init
lcd.init();
lcd.backlight();
inputString.reserve(10);
// Print something
lcd.setCursor(0, 0);
/*lcd.print("Hello, world!");
lcd.setCursor(2, 1);
lcd.print("Wokwi Online IoT");
lcd.setCursor(5, 2);
lcd.print("Simulator");
lcd.setCursor(7, 3);
lcd.print("Enjoy!");*/
//Keypad setup
Serial.begin(9600);
}
void loop() {
//lcd.clear();
char key = keypad.getKey();
lcd.setCursor(0,0);
lcd.print("rot= ");
lcd.print(inputString);
if (key) {
//lcd.println(inputString);
if (key >= '0' && key <= '9') { // only act on numeric keys
inputString += key; // append new character to input string
} else if (key == '#') {
if (inputString.length() > 0) {
inputInt = inputString.toInt(); // convert to int
inputString = ""; // clear input
// DO YOUR WORK HERE
lcd.setCursor(0,1);
//lcd.print("rot= ");
//lcd.print(inputInt);
//delay(3000);
if(inputInt>30)
{lcd.setCursor(0,1);
lcd.print("Eingabe zu hoch");
}
else
lcd.setCursor(0,1);
lcd.print("Eingabe erfolgt");
}
}
else if (key == '*')
{inputInt=0;
inputString = "";
lcd.clear(); // clear input
}
}}