Interrupt-driven keypad interface library. Compatible with RTOS. Able to handle various keypad size below 4x4.

Dependencies:   keypad mbed

Committer:
yoonghm
Date:
Wed Jan 01 17:47:52 2014 +0000
Revision:
1:1ae4a77af85b
Parent:
0:8209bcf62e0a
Interrupt-driven keypad interface library.; Can be used safely with RTOS.; Able to handle keypad size 4x4 and below.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yoonghm 0:8209bcf62e0a 1 #include "mbed.h"
yoonghm 0:8209bcf62e0a 2
yoonghm 1:1ae4a77af85b 3 #include "Keypad.h"
yoonghm 1:1ae4a77af85b 4
yoonghm 1:1ae4a77af85b 5 Serial PC(USBTX, USBRX);
yoonghm 0:8209bcf62e0a 6
yoonghm 0:8209bcf62e0a 7 // Define your own keypad values
yoonghm 1:1ae4a77af85b 8 char Keytable[] = { '1', '2', '3', // r0
yoonghm 1:1ae4a77af85b 9 '4', '5', '6', // r1
yoonghm 1:1ae4a77af85b 10 '7', '8', '9', // r2
yoonghm 1:1ae4a77af85b 11 // c0 c1 c2
yoonghm 0:8209bcf62e0a 12 };
yoonghm 0:8209bcf62e0a 13
yoonghm 1:1ae4a77af85b 14 int32_t Index = -1;
yoonghm 1:1ae4a77af85b 15 int State;
yoonghm 0:8209bcf62e0a 16
yoonghm 1:1ae4a77af85b 17 uint32_t cbAfterInput(uint32_t index)
yoonghm 1:1ae4a77af85b 18 {
yoonghm 1:1ae4a77af85b 19 Index = index;
yoonghm 0:8209bcf62e0a 20 return 0;
yoonghm 0:8209bcf62e0a 21 }
yoonghm 0:8209bcf62e0a 22
yoonghm 1:1ae4a77af85b 23 int main()
yoonghm 1:1ae4a77af85b 24 {
yoonghm 1:1ae4a77af85b 25 PC.printf("I am Demo Keypad\r\n");
yoonghm 1:1ae4a77af85b 26
yoonghm 1:1ae4a77af85b 27 // r0 r1 r2 r3 c0 c1 c2 c3
yoonghm 1:1ae4a77af85b 28 Keypad keypad(p21, p22, NC, NC, p23, p24, NC, NC);
yoonghm 1:1ae4a77af85b 29 keypad.attach(&cbAfterInput);
yoonghm 1:1ae4a77af85b 30 keypad.start(); // energize the columns c0-c3 of the keypad
yoonghm 0:8209bcf62e0a 31
yoonghm 0:8209bcf62e0a 32 while (1) {
yoonghm 1:1ae4a77af85b 33 __wfi();
yoonghm 1:1ae4a77af85b 34 if (Index > -1) {
yoonghm 1:1ae4a77af85b 35 PC.printf("Interrupted");
yoonghm 1:1ae4a77af85b 36 PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
yoonghm 1:1ae4a77af85b 37 Index = -1;
yoonghm 1:1ae4a77af85b 38 }
yoonghm 0:8209bcf62e0a 39 }
yoonghm 1:1ae4a77af85b 40 }