#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const byte hoch =19;
const byte runter = 2;
const byte links = 3;
const byte rechts =18;
const byte set = 4;
//const byte reset = ;
int pos_x = 0;
int pos_y = 0;
int btn_hoch = 0;
int btn_runter = 0;
int btn_links = 0;
int btn_rechts = 0;
int btn_set = 0;
int AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,MA,NA,OA,PA,QA,RA,SA,TA;
int AB,BB,CB,DB,EB,FB,GB,HB,IB,JB,KB,LB,MB,NB,OB,PB,QB,RB,SB,TB;
int AC,BC,CC,DC,EC,FC,GC,HC,IC,JC,KC,LC,MC,NC,OC,PC,QC,RC,SC,TC;
int AD,BD,CD,DD,ED,FD,GD,HD,ID,JD,KD,LD,MD,ND,OD,PD,QD,RD,SD,TD;
void btn_change(){
if(digitalRead(19) == LOW){
btn_hoch ++;
}
else if(digitalRead(2) == LOW){
btn_runter ++;
}
else if(digitalRead(3) == LOW){
btn_links ++;
}
else if(digitalRead(18) == LOW){
btn_rechts ++;
}
}
void btn_reset(){
btn_hoch = 0;
btn_runter = 0;
btn_links = 0;
btn_rechts = 0;
}
void pos_change(){
if(btn_hoch == 1){
pos_y --;
if(pos_y == -1){
pos_y ++;
}
btn_reset();
}
else if(btn_runter == 1){
pos_y ++;
if(pos_y == 4){
pos_y --;
}
btn_reset();
}
else if(btn_links == 1){
pos_x --;
if(pos_x == -1){
pos_x ++;
}
btn_reset();
}
else if(btn_rechts == 1){
pos_x ++;
if(pos_x == 20){
pos_x --;
}
btn_reset();
}
}
void blink(){
lcd.setCursor(pos_x, pos_y);
lcd.print("O");
delay(200);
lcd.setCursor(pos_x, pos_y);
lcd.print(" ");
pos_change();
delay(200);
}
void btn_SET(){
if(digitalRead(set)== LOW){
btn_set = 1;
}
}
void pm(){
while(btn_set == 1){
if(pos_x == 0 && pos_y == 0){
AA = 1;
break;
} else if(pos_x == 1 && pos_y == 0){
BA = 1;
break;
} else if(pos_x == 2 && pos_y == 0){
CA = 1;
break;
} else if(pos_x == 3 && pos_y == 0){
DA == 1;
break;
} else if(pos_x == 4 && pos_y == 0){
EA = 1;
break;
} else if(pos_x == 5 && pos_y == 0){
FA = 1;
break;
} else if(pos_x == 6 && pos_y == 0){
GA = 1;
break;
} else if(pos_x == 7 && pos_y == 0){
HA = 1;
break;
} else if(pos_x == 8 && pos_y == 0){
IA = 1;
break;
} else if(pos_x == 9 && pos_y == 0){
JA = 1;
break;
} else if(pos_x == 10 && pos_y == 0){
KA = 1;
break;
} else if(pos_x == 11 && pos_y == 0){
LA = 1;
break;
} else if(pos_x == 12 && pos_y == 0){
MA = 1;
break;
}
}
}
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
pinMode(hoch, INPUT_PULLUP);
pinMode(runter, INPUT_PULLUP);
pinMode(links, INPUT_PULLUP);
pinMode(rechts, INPUT_PULLUP);
pinMode(set, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(18), btn_change, FALLING);
attachInterrupt(digitalPinToInterrupt(3), btn_change, FALLING);
attachInterrupt(digitalPinToInterrupt(19), btn_change, FALLING);
attachInterrupt(digitalPinToInterrupt(2), btn_change, FALLING);
lcd.setCursor(pos_x, pos_y);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
blink();
btn_SET();
pm();
}