#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
//#define KEYTOINT(key) ((key) - '0')
#include "ge_txt.h"
//#include "en_txt.h"
LiquidCrystal_I2C lcd(0x27,20,4);
Servo servo;
const uint8_t ROWS = 4;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
{ '1', '2', '3' },
{ '4', '5', '6' },
{ '7', '8', '9' },
{ 'B', '0', 'E' }
};
uint8_t colPins[COLS] = {5, 4, 3};
uint8_t rowPins[ROWS] = {9, 8, 7, 6 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int zahl = 0;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print(title);
lcd.setCursor(4,2);
lcd.print(author);
delay(5000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(angle);
lcd.setCursor(0,1);
lcd.print("> 0");
servo.attach(10);
servo.write(0);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY)
{
switch(key)
{
case 'B':
zahl /= 10;
printResult();
break;
case 'E':
servo.write(zahl);
zahl = 0;
printResult();
break;
default:
zahl = zahl*10 + KeyToInt(key);
if(zahl>180)
{
lcd.setCursor(0,3);
lcd.print(error);
zahl = 0;
}
else
{
lcd.setCursor(0,3);
lcd.print(" ");
}
printResult();
break;
}
}
}
int KeyToInt(char key)
{
return(key - '0');
}
void printResult()
{
lcd.setCursor(2,1);
lcd.print(zahl);
lcd.print(" ");
}