![](/media/cache/profiles/f0fcf351df4eb6786e9bb6fc4e2dee02.jpg.50x50_q85.jpg)
Keypad program runs on OS2. Extended not only 3x4 but 4x4,4x5 and 5x5 keys.
see /users/kenjiArai/notebook/keypadkey-matrix--control/
Diff: key_4x4.cpp
- Revision:
- 2:d0ae519c229c
- Child:
- 3:8a7b6370956f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/key_4x4.cpp Mon Apr 06 04:59:45 2020 +0000 @@ -0,0 +1,59 @@ +/* + * Mbed Application program + * + * Copyright (c) 2020 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Created: April 5th, 2020 + * Revised: April 6th, 2020 + */ + +// Pre-selection -------------------------------------------------------------- +#include "select_example.h" +//#define KEY4X4 +#ifdef KEY4X4 + +// Include -------------------------------------------------------------------- +#include "mbed.h" +#include "Keypad.h" + +// Definition ----------------------------------------------------------------- + +// Object --------------------------------------------------------------------- +DigitalOut my_led(LED1); +Serial pc(USBTX,USBRX); +// X Y Z W A B C D OUT(XYZW), IN(ABCD) +Keypad key(D10, D9, D8, D7, D6, D5, D4, D3); + +// RAM ------------------------------------------------------------------------ + +// ROM / Constant data -------------------------------------------------------- +// X*A = *, X*B = 7, X*C = 4, X*D = 1 +// Y*A = 0, Y*B = 8, Y*C = 5, Y*D = 2 +// Z*A = #, Z*B = 9, Z*C = 6, Z*D = 3 +// W*A = A, W*B = B, W*C = C, W*D = D +// key_table[0]=? is not used! +const char *const key_table = "?*7410852#963ABCD"; +// 1234567890123456 + +// Function prototypes -------------------------------------------------------- + +//------------------------------------------------------------------------------ +// Control Program +//------------------------------------------------------------------------------ +int main() +{ + uint32_t key_num; + uint32_t counter = 0; + + pc.printf("Start Key-Pad test\r\n"); + while(true) { + while ((key_num = key.read()) != 0) { + pc.printf("%2u:[%2d] %c\r\n", + counter++, key_num, *(key_table + key_num)); + } + wait_us(100000); + } +} + +#endif // #ifdef KEY4X4 \ No newline at end of file