Tests forked Keypad library.

Dependencies:   FPointer keypad mbed

Schematic:

http://schind.nl/keypad.png

No extra hardware is needed besides the wires and switches. The columns are outputs configured with open drain. The rows are inputs configured with pull up resistors. A key press pulls down its row. With scanning the column is determined thereafter.

See keypad for the forked library used in this project.

Committer:
gj_schoneveld
Date:
Fri Nov 02 22:52:44 2012 +0000
Revision:
0:5410e5950602
Child:
1:8bbe2b267de6
Tests forked Keypad library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gj_schoneveld 0:5410e5950602 1 #include "mbed.h"
gj_schoneveld 0:5410e5950602 2 #include "keypad.h"
gj_schoneveld 0:5410e5950602 3
gj_schoneveld 0:5410e5950602 4 #define KEYLEN 4
gj_schoneveld 0:5410e5950602 5 #define ENDKEY 15
gj_schoneveld 0:5410e5950602 6 char Buffer[KEYLEN];
gj_schoneveld 0:5410e5950602 7 int Index = 0;
gj_schoneveld 0:5410e5950602 8
gj_schoneveld 0:5410e5950602 9 // Define your own keypad values
gj_schoneveld 0:5410e5950602 10 char Keytable[] = { '1', '2', '3', 'A',
gj_schoneveld 0:5410e5950602 11 '4', '5', '6', 'B',
gj_schoneveld 0:5410e5950602 12 '7', '8', '9', 'C',
gj_schoneveld 0:5410e5950602 13 '*', '0', '#', 'D'
gj_schoneveld 0:5410e5950602 14 };
gj_schoneveld 0:5410e5950602 15
gj_schoneveld 0:5410e5950602 16 uint32_t cbAfterInput(uint32_t key)
gj_schoneveld 0:5410e5950602 17 {
gj_schoneveld 0:5410e5950602 18 bool finish = false;
gj_schoneveld 0:5410e5950602 19
gj_schoneveld 0:5410e5950602 20 printf("Index:%d => Key:%c\n", Index, Keytable[key]);
gj_schoneveld 0:5410e5950602 21
gj_schoneveld 0:5410e5950602 22 if (Index < KEYLEN - 1) {
gj_schoneveld 0:5410e5950602 23 if (key != ENDKEY) // Terminating key
gj_schoneveld 0:5410e5950602 24 Buffer[Index] = Keytable[key];
gj_schoneveld 0:5410e5950602 25 else // Terminating key is entered
gj_schoneveld 0:5410e5950602 26 finish = true;
gj_schoneveld 0:5410e5950602 27 Index++;
gj_schoneveld 0:5410e5950602 28 }
gj_schoneveld 0:5410e5950602 29
gj_schoneveld 0:5410e5950602 30 if (finish || (Index == KEYLEN - 1)) {
gj_schoneveld 0:5410e5950602 31 printf("Complete string = %s\n", Buffer);
gj_schoneveld 0:5410e5950602 32 memset(&Buffer, 0, KEYLEN);
gj_schoneveld 0:5410e5950602 33 Index = 0;
gj_schoneveld 0:5410e5950602 34 }
gj_schoneveld 0:5410e5950602 35
gj_schoneveld 0:5410e5950602 36 return 0;
gj_schoneveld 0:5410e5950602 37 }
gj_schoneveld 0:5410e5950602 38
gj_schoneveld 0:5410e5950602 39 void Sleep(void)
gj_schoneveld 0:5410e5950602 40 {
gj_schoneveld 0:5410e5950602 41 __WFI();
gj_schoneveld 0:5410e5950602 42 }
gj_schoneveld 0:5410e5950602 43
gj_schoneveld 0:5410e5950602 44 int main()
gj_schoneveld 0:5410e5950602 45 {
gj_schoneveld 0:5410e5950602 46 printf("*** Keypad Demo ***\n");
gj_schoneveld 0:5410e5950602 47
gj_schoneveld 0:5410e5950602 48 memset(&Buffer, 0, KEYLEN);
gj_schoneveld 0:5410e5950602 49 Index = 0;
gj_schoneveld 0:5410e5950602 50 Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24);
gj_schoneveld 0:5410e5950602 51 keypad.CallAfterInput(&cbAfterInput);
gj_schoneveld 0:5410e5950602 52
gj_schoneveld 0:5410e5950602 53 keypad.Start();
gj_schoneveld 0:5410e5950602 54 while (1) {
gj_schoneveld 0:5410e5950602 55 Sleep();
gj_schoneveld 0:5410e5950602 56 }
gj_schoneveld 0:5410e5950602 57 }