#include <LiquidCrystal_I2C.h>
#define Set1(r,b) r|=1<<b
#define Set0(r,b) r&=~(1<<b)
#define test(r,b) (r&(1<<b))
LiquidCrystal_I2C lcd(0x27,16,2);
byte prerusenie;
String s;
void setup() {
lcd.init();
lcd.backlight();
for(int i = 4;i<8;i++){
Set0(DDRD,i);
Set1(PORTD,i);
}
Set1(PCICR,PCIE2);
Set1(PCIFR,PCIF2);
Set1(SREG,7);
Set1(PCMSK2,PCINT20);
Set1(PCMSK2,PCINT21);
Set1(PCMSK2,PCINT22);
Set1(PCMSK2,PCINT23);
prerusenie = PIND;
}
bool ano = false;
void loop() {
if(ano){
lcd.clear();
lcd.print(s);
ano = false;
}
}
ISR(PCINT2_vect){
if(test(PIND,4) == 0 && test(prerusenie,4) != test(PIND,4)){
s = "A";
ano = true;
}
if(test(PIND,5) == 0 && test(prerusenie,5) != test(PIND,5)){
s = "B";
ano = true;
}
if(test(PIND,6) == 0 && test(prerusenie,6) != test(PIND,6)){
s = "C";
ano = true;
}
if(test(PIND,7) == 0 && test(prerusenie,7) != test(PIND,7)){
s = "D";
ano = true;
}
prerusenie = PIND;
}