test program for keypad(Extended not only 3x4 but 4x4,4x5 and 5x5 keys)
Fork of study_step0 by
see /users/kenjiArai/notebook/keypadkey-matrix--control/
key_4x5.cpp@4:0564f82dd0ef, 2020-08-01 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Aug 01 07:49:39 2020 +0000
- Revision:
- 4:0564f82dd0ef
- Parent:
- 3:0c888cad9376
- Child:
- 5:53fb9eed6b67
changed pc.printf to printf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 2:aa6fdecebf2b | 1 | /* |
kenjiArai | 2:aa6fdecebf2b | 2 | * Mbed Application program |
kenjiArai | 2:aa6fdecebf2b | 3 | * |
kenjiArai | 2:aa6fdecebf2b | 4 | * Copyright (c) 2020 Kenji Arai / JH1PJL |
kenjiArai | 2:aa6fdecebf2b | 5 | * http://www7b.biglobe.ne.jp/~kenjia/ |
kenjiArai | 2:aa6fdecebf2b | 6 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 2:aa6fdecebf2b | 7 | * Created: April 5th, 2020 |
kenjiArai | 4:0564f82dd0ef | 8 | * Revised: August 1st, 2020 |
kenjiArai | 2:aa6fdecebf2b | 9 | */ |
kenjiArai | 2:aa6fdecebf2b | 10 | |
kenjiArai | 2:aa6fdecebf2b | 11 | // Pre-selection -------------------------------------------------------------- |
kenjiArai | 2:aa6fdecebf2b | 12 | #include "select_example.h" |
kenjiArai | 2:aa6fdecebf2b | 13 | //#define KEY4X5 |
kenjiArai | 2:aa6fdecebf2b | 14 | #ifdef KEY4X5 |
kenjiArai | 2:aa6fdecebf2b | 15 | |
kenjiArai | 2:aa6fdecebf2b | 16 | // Include -------------------------------------------------------------------- |
kenjiArai | 2:aa6fdecebf2b | 17 | #include "mbed.h" |
kenjiArai | 2:aa6fdecebf2b | 18 | #include "Keypad.h" |
kenjiArai | 2:aa6fdecebf2b | 19 | |
kenjiArai | 2:aa6fdecebf2b | 20 | // Definition ----------------------------------------------------------------- |
kenjiArai | 2:aa6fdecebf2b | 21 | |
kenjiArai | 2:aa6fdecebf2b | 22 | // Object --------------------------------------------------------------------- |
kenjiArai | 2:aa6fdecebf2b | 23 | DigitalOut my_led(LED1); |
kenjiArai | 3:0c888cad9376 | 24 | // X Y Z W A B C D E OUT(XYZW), IN(ABCDE) |
kenjiArai | 3:0c888cad9376 | 25 | Keypad key(D11, D10, D9, D8, D6, D5, D4, D3, D2); |
kenjiArai | 2:aa6fdecebf2b | 26 | |
kenjiArai | 2:aa6fdecebf2b | 27 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 2:aa6fdecebf2b | 28 | |
kenjiArai | 2:aa6fdecebf2b | 29 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 2:aa6fdecebf2b | 30 | // X*A = *, X*B = D, X*C = 9, X*D = 5, X*E = 1 |
kenjiArai | 2:aa6fdecebf2b | 31 | // Y*A = /, Y*B = E, Y*C = A, Y*D = 6, Y*E = 2 |
kenjiArai | 2:aa6fdecebf2b | 32 | // Z*A = #, Z*B = F, Z*C = B, Z*D = 7, Z*E = 3 |
kenjiArai | 2:aa6fdecebf2b | 33 | // W*A = +, W*B = G, W*C = C, W*D = 8, W*E = 4 |
kenjiArai | 2:aa6fdecebf2b | 34 | // key_table[0]=? is not used! |
kenjiArai | 2:aa6fdecebf2b | 35 | const char *const key_table = "?*D951/EA62#FB73+GC84"; |
kenjiArai | 2:aa6fdecebf2b | 36 | // 12345678901234567890 |
kenjiArai | 2:aa6fdecebf2b | 37 | |
kenjiArai | 2:aa6fdecebf2b | 38 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 2:aa6fdecebf2b | 39 | |
kenjiArai | 2:aa6fdecebf2b | 40 | //------------------------------------------------------------------------------ |
kenjiArai | 2:aa6fdecebf2b | 41 | // Control Program |
kenjiArai | 2:aa6fdecebf2b | 42 | //------------------------------------------------------------------------------ |
kenjiArai | 2:aa6fdecebf2b | 43 | int main() |
kenjiArai | 2:aa6fdecebf2b | 44 | { |
kenjiArai | 2:aa6fdecebf2b | 45 | uint32_t key_num; |
kenjiArai | 2:aa6fdecebf2b | 46 | uint32_t counter = 0; |
kenjiArai | 2:aa6fdecebf2b | 47 | |
kenjiArai | 4:0564f82dd0ef | 48 | printf("Start Key-Pad test 4x5 keys\r\n"); |
kenjiArai | 2:aa6fdecebf2b | 49 | while(true) { |
kenjiArai | 2:aa6fdecebf2b | 50 | while ((key_num = key.read()) != 0) { |
kenjiArai | 4:0564f82dd0ef | 51 | printf("%2u:[%2d] %c\r\n", |
kenjiArai | 2:aa6fdecebf2b | 52 | counter++, key_num, *(key_table + key_num)); |
kenjiArai | 2:aa6fdecebf2b | 53 | } |
kenjiArai | 2:aa6fdecebf2b | 54 | wait_us(100000); |
kenjiArai | 2:aa6fdecebf2b | 55 | } |
kenjiArai | 2:aa6fdecebf2b | 56 | } |
kenjiArai | 2:aa6fdecebf2b | 57 | |
kenjiArai | 2:aa6fdecebf2b | 58 | #endif // #ifdef KEY4X5 |