#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
LiquidCrystal_I2C lcd (0x27,3,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' },
{ 'L', '0', 'S' }
};
uint8_t colPins[COLS] = {4, 3, 2}; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = {8, 7, 6, 5 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int pchar = 0xFF;
const int mchar = 0x20;
int i = 0;
const int Poti = A0;
int adc = 0;
int angel = 0;
int fsave = 0;
int fdelete = 0;
int graph = 0;
int val[] = {0,0,0,0,0,0,0,0,0,0};
int zahl = 0;
void setup()
{
lcd.init();
lcd.backlight();
servo.attach(9);
servo.write(0);
}
void loop(){
char key = keypad.getKey();
if (key != NO_KEY)
{
switch(key)
{
case 'S':
break;
case 'L':
break;
default:
i = key - '0';
break;
}}
adc = analogRead(A0);
angel = map(adc,0,1023,0,180);
graph = map(adc,0,1023,0,COLS);
barGraph(graph, COLS, 3, pchar, mchar);
adc = analogRead(Poti);
lcd.setCursor(0,0);
lcd.print("Mem[");
lcd.print(i);
lcd.print("]: ");
lcd.setCursor(0,1);
lcd.print("adc: ");
lcd.print(adc); //gibt werte von 0-1023 in Binär / display.print(adc); gibt den wert von 0-1023
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print("angel: ");
lcd.print(angel);
lcd.print (" ");
if(fsave)
{
servo.write(angel);
fsave = 0;
}
if(fdelete)
{
servo.write(0);
fdelete = 0;
}
}
void barGraph(int anzSeg, int maxCol, int row, int pchar, int mchar)
{
int i = 0;
for(i = 0;i < maxCol; i++)
{
lcd.setCursor(i,row);
if(i < anzSeg)lcd.write(pchar);
else lcd.write(mchar);
}
}