Created
November 25, 2022 17:54
-
-
Save michalmonday/8db7ba2caa29187d01b392df28c306f3 to your computer and use it in GitHub Desktop.
Mbed extension board alternative keypad reading.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
Serial pc(USBTX, USBRX); // tx, rx | |
BusOut cols_out(p26, p25, p24); | |
// Checking extension board with multimeter shows that p14,p13,p12,p11 are connected | |
// to row indicating pins of the keypad. The extension board schematic is incorrect. | |
BusIn rows_in(p14, p13, p12, p11); | |
char Keytable[][4] = { | |
{'1', '2', '3', 'F'}, | |
{'4', '5', '6', 'E'}, | |
{'7', '8', '9', 'D'}, | |
{'A', '0', 'B', 'C'} | |
}; | |
char getKey() { | |
int i,j; | |
for (i = 0; i <= 3; i++) { | |
cols_out = i; | |
// for each bit in rows | |
for (j = 0; j <= 3; j++) { | |
// if j'th bit of "rows_in" is LOW | |
if (~rows_in & (1 << j)) { | |
return Keytable[j][3-i]; | |
} | |
} | |
} | |
return ' '; | |
} | |
int main() { | |
char key = ' '; | |
while(1) { | |
key = getKey(); | |
if(key != ' ') { | |
pc.printf("Key = %c\r\n", key); | |
wait(0.3); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment