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 06 04:59:45 2020 +0000
Revision:
2:d0ae519c229c
Child:
3:8a7b6370956f
Keypad program runs on OS2

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 2:d0ae519c229c 8 * Revised: April 6th, 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 COMPLEX
kenjiArai 2:d0ae519c229c 14 #ifdef COMPLEX
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 #define A_SW 24 // see key_table[25] = A
kenjiArai 2:d0ae519c229c 22 #define B_SW 3 // see key_table[3] = B
kenjiArai 2:d0ae519c229c 23 #define C_SW 8 // see key_table[8] = C
kenjiArai 2:d0ae519c229c 24
kenjiArai 2:d0ae519c229c 25 // Object ---------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 26 DigitalOut my_led(D13);
kenjiArai 2:d0ae519c229c 27 //DigitalOut my_led(LED1);
kenjiArai 2:d0ae519c229c 28 DigitalOut led0(A0);
kenjiArai 2:d0ae519c229c 29 DigitalOut led1(A1);
kenjiArai 2:d0ae519c229c 30 DigitalOut led2(A2);
kenjiArai 2:d0ae519c229c 31 Serial pc(USBTX,USBRX);
kenjiArai 2:d0ae519c229c 32 // X Y Z W V A B C D E OUT(XYZWV), IN(ABCDE)
kenjiArai 2:d0ae519c229c 33 Keypad key(D6, D5, D4, D3, D2, D11, D10, D9, D8, D7);
kenjiArai 2:d0ae519c229c 34
kenjiArai 2:d0ae519c229c 35 // RAM ------------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 36
kenjiArai 2:d0ae519c229c 37 // ROM / Constant data --------------------------------------------------------
kenjiArai 2:d0ae519c229c 38 // key_table[0]=? is not used!
kenjiArai 2:d0ae519c229c 39 // 1 2 3 4 5
kenjiArai 2:d0ae519c229c 40 const char key_table[] = {NUL,
kenjiArai 2:d0ae519c229c 41 '*', 'G', 'B', '6', '1', // 1
kenjiArai 2:d0ae519c229c 42 '/', 'H', 'C', '7', '2', // 2
kenjiArai 2:d0ae519c229c 43 CR, '-', 'D', '8', '3', // 3
kenjiArai 2:d0ae519c229c 44 SPC, '+', 'E', '9', '4', // 4
kenjiArai 2:d0ae519c229c 45 BS, '=', 'F', 'A', '5', // 5
kenjiArai 2:d0ae519c229c 46 NUL
kenjiArai 2:d0ae519c229c 47 };
kenjiArai 2:d0ae519c229c 48
kenjiArai 2:d0ae519c229c 49 // Function prototypes --------------------------------------------------------
kenjiArai 2:d0ae519c229c 50
kenjiArai 2:d0ae519c229c 51 //------------------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 52 // Control Program
kenjiArai 2:d0ae519c229c 53 //------------------------------------------------------------------------------
kenjiArai 2:d0ae519c229c 54 int main()
kenjiArai 2:d0ae519c229c 55 {
kenjiArai 2:d0ae519c229c 56 uint32_t key_num;
kenjiArai 2:d0ae519c229c 57 uint32_t counter = 0;
kenjiArai 2:d0ae519c229c 58
kenjiArai 2:d0ae519c229c 59 pc.printf("Start Key-Pad test\r\n");
kenjiArai 2:d0ae519c229c 60 while(true) {
kenjiArai 2:d0ae519c229c 61 while ((key_num = key.read()) != 0) {
kenjiArai 2:d0ae519c229c 62 pc.printf("%2u:[%2d] %c\r\n",
kenjiArai 2:d0ae519c229c 63 counter++, key_num, key_table[key_num]);
kenjiArai 2:d0ae519c229c 64 }
kenjiArai 2:d0ae519c229c 65 if (key.read_state(A_SW) == true) {
kenjiArai 2:d0ae519c229c 66 led0 = 1;
kenjiArai 2:d0ae519c229c 67 } else {
kenjiArai 2:d0ae519c229c 68 led0 = 0;
kenjiArai 2:d0ae519c229c 69 }
kenjiArai 2:d0ae519c229c 70 if (key.read_state(B_SW) == true) {
kenjiArai 2:d0ae519c229c 71 led1 = 1;
kenjiArai 2:d0ae519c229c 72 } else {
kenjiArai 2:d0ae519c229c 73 led1 = 0;
kenjiArai 2:d0ae519c229c 74 }
kenjiArai 2:d0ae519c229c 75 if (key.read_state(C_SW) == true) {
kenjiArai 2:d0ae519c229c 76 led2 = 1;
kenjiArai 2:d0ae519c229c 77 } else {
kenjiArai 2:d0ae519c229c 78 led2 = 0;
kenjiArai 2:d0ae519c229c 79 }
kenjiArai 2:d0ae519c229c 80 wait_us(100000);
kenjiArai 2:d0ae519c229c 81 }
kenjiArai 2:d0ae519c229c 82 }
kenjiArai 2:d0ae519c229c 83
kenjiArai 2:d0ae519c229c 84 #endif // #ifdef COMPLEX