Gert Jan Schoneveld / Mbed 2 deprecated SaveKeypad

Dependencies:   FPointer keypad mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "keypad.h"
00003 
00004 // Define your own keypad values
00005 char Keytable[] = { '1', '2', '3', 'A',
00006                     '4', '5', '6', 'B',
00007                     '7', '8', '9', 'C',
00008                     '*', '0', '#', 'D'
00009                   };
00010 
00011 BusOut code(LED4, LED3, LED2, LED1); //show binary code of key
00012 
00013 uint32_t cbAfterInput(uint32_t key)
00014 {
00015     printf("Key: %d => \'%c\'\n", key, Keytable[key]);
00016     code = key;
00017 
00018     return 0;
00019 }
00020 
00021 uint32_t cbAfterMultipleInput(uint32_t key)
00022 {
00023     for (int i = 0; i < 16; i++) {
00024         if (key & (1 << i)) {
00025              printf("Key: %d => \'%c\'\t", i, Keytable[i]);
00026         }
00027     }
00028     printf("\n");
00029     code = key;
00030 
00031     return 0;
00032 }
00033 
00034 void Sleep(void)
00035 {
00036     __WFI();
00037 }
00038 
00039 int main()
00040 {
00041     printf("*** Keypad Demo ***\n");
00042 
00043     Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24);
00044 
00045 // interrupt mode
00046 /*
00047     keypad.CallAfterInput(&cbAfterInput);
00048     keypad.Start();
00049     while (1) {
00050         Sleep();
00051     }
00052 */
00053     
00054 // polling mode
00055 /*
00056     keypad.Start();
00057     while (1) {
00058         int key = keypad.DebouncedScan();
00059         if (key >= 0)
00060             cbAfterInput(key);
00061         wait(0.1);
00062     }
00063 */
00064 
00065 // poll multiple mode
00066     keypad.Start();
00067     while (1) {
00068         int key = keypad.DebouncedScanMultiple();
00069         if (key > 0)
00070             cbAfterMultipleInput(key);
00071         wait(0.1);
00072     }
00073 }