Keypad program runs on OS2. Extended not only 3x4 but 4x4,4x5 and 5x5 keys.

Dependencies:   mbed Keypad

see /users/kenjiArai/notebook/keypadkey-matrix--control/

Committer:
kenjiArai
Date:
Mon Apr 13 02:07:27 2020 +0000
Revision:
3:8a7b6370956f
Parent:
2:d0ae519c229c
modified keypad library and changed port assign

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 2:d0ae519c229c 1 /*
kenjiArai 2:d0ae519c229c 2 * Mbed Application program
kenjiArai 2:d0ae519c229c 3 *
kenjiArai 2:d0ae519c229c 4 * Copyright (c) 2020 Kenji Arai / JH1PJL
kenjiArai 2:d0ae519c229c 5 * http://www7b.biglobe.ne.jp/~kenjia/
kenjiArai 2:d0ae519c229c 6 * https://os.mbed.com/users/kenjiArai/
kenjiArai 2:d0ae519c229c 7 * Created: April 5th, 2020
kenjiArai 3:8a7b6370956f 8 * Revised: April 13th, 2020
kenjiArai 2:d0ae519c229c 9 */
kenjiArai 2:d0ae519c229c 10
kenjiArai 2:d0ae519c229c 11 // Pre-selection --------------------------------------------------------------
kenjiArai 2:d0ae519c229c 12 #include "select_example.h"
kenjiArai 2:d0ae519c229c 13 //#define KEY5X5
kenjiArai 2:d0ae519c229c 14 #ifdef KEY5X5
kenjiArai 2:d0ae519c229c 15
kenjiArai 2:d0ae519c229c 16 // Include --------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 17 #include "mbed.h"
kenjiArai 2:d0ae519c229c 18 #include "Keypad.h"
kenjiArai 2:d0ae519c229c 19
kenjiArai 2:d0ae519c229c 20 // Definition -----------------------------------------------------------------
kenjiArai 2:d0ae519c229c 21
kenjiArai 2:d0ae519c229c 22 // Object ---------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 23 DigitalOut my_led(LED1);
kenjiArai 2:d0ae519c229c 24 Serial pc(USBTX,USBRX);
kenjiArai 2:d0ae519c229c 25 // X Y Z W V A B C D E OUT(XYZWV), IN(ABCDE)
kenjiArai 2:d0ae519c229c 26 Keypad key(D11, D10, D9, D8, D7, D6, D5, D4, D3, D2);
kenjiArai 2:d0ae519c229c 27
kenjiArai 2:d0ae519c229c 28 // RAM ------------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 29
kenjiArai 2:d0ae519c229c 30 // ROM / Constant data --------------------------------------------------------
kenjiArai 2:d0ae519c229c 31 // X*A = *, X*B = G, X*C = B, X*D = 6, X*E = 1
kenjiArai 2:d0ae519c229c 32 // Y*A = /, Y*B = H, Y*C = C, Y*D = 7, Y*E = 2
kenjiArai 2:d0ae519c229c 33 // Z*A = ., Z*B = I, Z*C = D, Z*D = 8, Z*E = 3
kenjiArai 2:d0ae519c229c 34 // W*A = +, W*B = J, W*C = E, W*D = 9, W*E = 4
kenjiArai 2:d0ae519c229c 35 // V*A = -, V*B = =, V*C = F, V*D = A, V*E = 5
kenjiArai 2:d0ae519c229c 36 // key_table[0]=? is not used!
kenjiArai 2:d0ae519c229c 37 const char *const key_table = "?*GB61/HC72.ID83+JE94-=FA5";
kenjiArai 2:d0ae519c229c 38 // 1234567890123456789012345
kenjiArai 2:d0ae519c229c 39
kenjiArai 2:d0ae519c229c 40 // Function prototypes --------------------------------------------------------
kenjiArai 2:d0ae519c229c 41
kenjiArai 2:d0ae519c229c 42 //------------------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 43 // Control Program
kenjiArai 2:d0ae519c229c 44 //------------------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 45 int main()
kenjiArai 2:d0ae519c229c 46 {
kenjiArai 2:d0ae519c229c 47 uint32_t key_num;
kenjiArai 2:d0ae519c229c 48 uint32_t counter = 0;
kenjiArai 2:d0ae519c229c 49
kenjiArai 3:8a7b6370956f 50 pc.printf("Start Key-Pad test 5x5 keys\r\n");
kenjiArai 2:d0ae519c229c 51 while(true) {
kenjiArai 2:d0ae519c229c 52 while ((key_num = key.read()) != 0) {
kenjiArai 2:d0ae519c229c 53 pc.printf("%2u:[%2d] %c\r\n",
kenjiArai 2:d0ae519c229c 54 counter++, key_num, *(key_table + key_num));
kenjiArai 2:d0ae519c229c 55 }
kenjiArai 2:d0ae519c229c 56 wait_us(100000);
kenjiArai 2:d0ae519c229c 57 }
kenjiArai 2:d0ae519c229c 58 }
kenjiArai 2:d0ae519c229c 59
kenjiArai 2:d0ae519c229c 60 #endif // #ifdef KEY5X5