Kenji Arai / Mbed 2 deprecated Keypad_input_OS2

Dependencies:   mbed Keypad

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers key_4x5.cpp Source File

key_4x5.cpp

00001 /*
00002  * Mbed Application program
00003  *
00004  * Copyright (c) 2020 Kenji Arai / JH1PJL
00005  *  http://www7b.biglobe.ne.jp/~kenjia/
00006  *  https://os.mbed.com/users/kenjiArai/
00007  *      Created:    April      5th, 2020
00008  *      Revised:    April     13th, 2020
00009  */
00010 
00011 //  Pre-selection --------------------------------------------------------------
00012 #include    "select_example.h"
00013 //#define KEY4X5
00014 #ifdef KEY4X5
00015 
00016 //  Include --------------------------------------------------------------------
00017 #include "mbed.h"
00018 #include "Keypad.h"
00019 
00020 //  Definition -----------------------------------------------------------------
00021 
00022 //  Object ---------------------------------------------------------------------
00023 DigitalOut  my_led(LED1);
00024 Serial      pc(USBTX,USBRX);
00025 //              X    Y    Z   W    A   B   C   D   E   OUT(XYZW), IN(ABCDE)
00026 Keypad      key(D11, D10, D9, D8, D6, D5, D4, D3, D2);
00027 
00028 //  RAM ------------------------------------------------------------------------
00029 
00030 //  ROM / Constant data --------------------------------------------------------
00031 //                          X*A = *, X*B = D, X*C = 9, X*D = 5, X*E = 1
00032 //                          Y*A = /, Y*B = E, Y*C = A, Y*D = 6, Y*E = 2
00033 //                          Z*A = #, Z*B = F, Z*C = B, Z*D = 7, Z*E = 3
00034 //                          W*A = +, W*B = G, W*C = C, W*D = 8, W*E = 4
00035 //                          key_table[0]=? is not used!
00036 const char *const key_table = "?*D951/EA62#FB73+GC84";
00037 //                              12345678901234567890
00038 
00039 //  Function prototypes --------------------------------------------------------
00040 
00041 //------------------------------------------------------------------------------
00042 //  Control Program
00043 //------------------------------------------------------------------------------
00044 int main()
00045 {
00046     uint32_t key_num;
00047     uint32_t counter = 0;
00048 
00049     pc.printf("Start Key-Pad test 4x5 keys\r\n");
00050     while(true) {
00051         while ((key_num = key.read()) != 0) {
00052             pc.printf("%2u:[%2d] %c\r\n",
00053                       counter++, key_num, *(key_table + key_num));
00054         }
00055         wait_us(100000);
00056     }
00057 }
00058 
00059 #endif  // #ifdef KEY4X5