Keypad program runs on OS2. Extended not only 3x4 but 4x4,4x5 and 5x5 keys.
see /users/kenjiArai/notebook/keypadkey-matrix--control/
key_3x4.cpp@2:d0ae519c229c, 2020-04-06 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 2:d0ae519c229c | 1 | /* |
kenjiArai | 2:d0ae519c229c | 2 | * Mbed Application program |
kenjiArai | 2:d0ae519c229c | 3 | * example: |
kenjiArai | 2:d0ae519c229c | 4 | * Akizuki AE-KIT45-KEYPAD4X3 |
kenjiArai | 2:d0ae519c229c | 5 | * http://akizukidenshi.com/catalog/g/gK-12229/ |
kenjiArai | 2:d0ae519c229c | 6 | * |
kenjiArai | 2:d0ae519c229c | 7 | * Copyright (c) 2017,'20 Kenji Arai / JH1PJL |
kenjiArai | 2:d0ae519c229c | 8 | * http://www7b.biglobe.ne.jp/~kenjia/ |
kenjiArai | 2:d0ae519c229c | 9 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 2:d0ae519c229c | 10 | * Created: September 27th, 2017 |
kenjiArai | 2:d0ae519c229c | 11 | * Revised: April 6th, 2020 |
kenjiArai | 2:d0ae519c229c | 12 | */ |
kenjiArai | 2:d0ae519c229c | 13 | |
kenjiArai | 2:d0ae519c229c | 14 | // Pre-selection -------------------------------------------------------------- |
kenjiArai | 2:d0ae519c229c | 15 | #include "select_example.h" |
kenjiArai | 2:d0ae519c229c | 16 | //#define KEY3X4 |
kenjiArai | 2:d0ae519c229c | 17 | #ifdef KEY3X4 |
kenjiArai | 2:d0ae519c229c | 18 | |
kenjiArai | 2:d0ae519c229c | 19 | // Include -------------------------------------------------------------------- |
kenjiArai | 2:d0ae519c229c | 20 | #include "mbed.h" |
kenjiArai | 2:d0ae519c229c | 21 | #include "Keypad.h" |
kenjiArai | 2:d0ae519c229c | 22 | |
kenjiArai | 2:d0ae519c229c | 23 | // Definition ----------------------------------------------------------------- |
kenjiArai | 2:d0ae519c229c | 24 | |
kenjiArai | 2:d0ae519c229c | 25 | // Object --------------------------------------------------------------------- |
kenjiArai | 2:d0ae519c229c | 26 | DigitalOut my_led(LED1); |
kenjiArai | 2:d0ae519c229c | 27 | Serial pc(USBTX,USBRX); |
kenjiArai | 2:d0ae519c229c | 28 | // X Y Z A B C D OUT(XYZ), IN(ABCD) |
kenjiArai | 2:d0ae519c229c | 29 | Keypad key(D10, D9, D8, D7, D6, D5, D4); |
kenjiArai | 2:d0ae519c229c | 30 | // X Y Z A B C D OUT(XYZ), IN(ABCD) |
kenjiArai | 2:d0ae519c229c | 31 | //Keypad key(D10, D9, D8, D6, D5, D4, D3); |
kenjiArai | 2:d0ae519c229c | 32 | |
kenjiArai | 2:d0ae519c229c | 33 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 2:d0ae519c229c | 34 | |
kenjiArai | 2:d0ae519c229c | 35 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 2:d0ae519c229c | 36 | // X*A = *, X*B = 7, X*C = 4, X*D = 1 |
kenjiArai | 2:d0ae519c229c | 37 | // Y*A = 0, Y*B = 8, Y*C = 5, Y*D = 2 |
kenjiArai | 2:d0ae519c229c | 38 | // Z*A = #, Z*B = 9, Z*C = 6, Z*D = 3 |
kenjiArai | 2:d0ae519c229c | 39 | // key_table[0]=? is not used! |
kenjiArai | 2:d0ae519c229c | 40 | const char *const key_table = "?*7410852#963"; |
kenjiArai | 2:d0ae519c229c | 41 | // 123456789012 |
kenjiArai | 2:d0ae519c229c | 42 | |
kenjiArai | 2:d0ae519c229c | 43 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 2:d0ae519c229c | 44 | |
kenjiArai | 2:d0ae519c229c | 45 | //------------------------------------------------------------------------------ |
kenjiArai | 2:d0ae519c229c | 46 | // Control Program |
kenjiArai | 2:d0ae519c229c | 47 | //------------------------------------------------------------------------------ |
kenjiArai | 2:d0ae519c229c | 48 | int main() |
kenjiArai | 2:d0ae519c229c | 49 | { |
kenjiArai | 2:d0ae519c229c | 50 | uint32_t key_num; |
kenjiArai | 2:d0ae519c229c | 51 | uint32_t counter = 0; |
kenjiArai | 2:d0ae519c229c | 52 | |
kenjiArai | 2:d0ae519c229c | 53 | pc.printf("Start Key-Pad test\r\n"); |
kenjiArai | 2:d0ae519c229c | 54 | while(true) { |
kenjiArai | 2:d0ae519c229c | 55 | while ((key_num = key.read()) != 0) { |
kenjiArai | 2:d0ae519c229c | 56 | pc.printf("%2u:[%2d] %c\r\n", |
kenjiArai | 2:d0ae519c229c | 57 | counter++, key_num, *(key_table + key_num)); |
kenjiArai | 2:d0ae519c229c | 58 | } |
kenjiArai | 2:d0ae519c229c | 59 | wait_us(100000); |
kenjiArai | 2:d0ae519c229c | 60 | } |
kenjiArai | 2:d0ae519c229c | 61 | } |
kenjiArai | 2:d0ae519c229c | 62 | |
kenjiArai | 2:d0ae519c229c | 63 | #endif // #ifdef KEY3X4 |