// void setup() {
// // put your setup code here, to run once:
// volatile char *dirF, *dirK, *dirA,*dirC;
// dirF=0x30, dirK=0x107,dirA=0x21,dirC=0x27;
// *dirF=0xFF, *dirK=0x00,*dirA=0xFF,*dirC=0xFF;
// volatile char *outF,*inK, *outA, *outC;
// outF=0x31, inK=0x106, outA=0x22 , outC=0x28 ;
// // *outA=0x0F;
// volatile long i,j;
// while(1){
// for( i=0; i<4; i++){
// *outF=1 << i;
// if(*inK !=0){
// *outA=*inK;
// *outC=1 <<i;
// for(j=0; j<100000;j++);
// }
// *outC=0;
// *outA=0;
// }
// }
// }
// void loop() {
// // put your main code here, to run repeatedly:
// }
#include <math.h>
void setup() {
// put your setup code here, to run once:
volatile char *dirF, *dirK, *dirA,*dirC;
dirF=0x30, dirK=0x107,dirA=0x21,dirC=0x27;
*dirF=0xFF, *dirK=0x00,*dirA=0xFF,*dirC=0xFF;
volatile char *outF,*inK, *outA, *outC;
outF=0x31, inK=0x106, outA=0x22 , outC=0x28 ;
Serial.begin(9600);
// *outA=0x0F;
volatile int col,row;
char keys[4][4] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'.', '0', '=', '/'}
};
volatile long i, j;
while(1) {
for(i = 0; i < 4; i++) {
*outF = 1 << i;
if(*inK != 0) {
col = *inK;
row = 1 << i;
*outC = row;
*outA = col;
Serial.print(keys[int(log(row) / log(2))][int(log(col) / log(2))]);
// Debounce delay for stable key press detection
delay(50);
// Wait for key release
while (*inK != 0);
// Turn off LEDs once key is released
*outC = 0;
*outA = 0;
}
delay(10); // Short delay between each iteration
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}