hima bindu pallanti
/
mbed_key
4*4 keypad interfacing with arm lpc1768 for entering 0-9 digits.
main.cpp@0:5e96fed89c06, 2015-10-10 (annotated)
- Committer:
- himabindupallanti
- Date:
- Sat Oct 10 10:35:00 2015 +0000
- Revision:
- 0:5e96fed89c06
Keypad interfacing for password
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
himabindupallanti | 0:5e96fed89c06 | 1 | #include "mbed.h" |
himabindupallanti | 0:5e96fed89c06 | 2 | |
himabindupallanti | 0:5e96fed89c06 | 3 | #include "Keypad.h" |
himabindupallanti | 0:5e96fed89c06 | 4 | |
himabindupallanti | 0:5e96fed89c06 | 5 | Serial PC(USBTX, USBRX); |
himabindupallanti | 0:5e96fed89c06 | 6 | |
himabindupallanti | 0:5e96fed89c06 | 7 | // Define your own keypad values |
himabindupallanti | 0:5e96fed89c06 | 8 | char Keytable[] = { '1', '2', '3', // r0 |
himabindupallanti | 0:5e96fed89c06 | 9 | '4', '5', '6', // r1 |
himabindupallanti | 0:5e96fed89c06 | 10 | '7', '8', '9', |
himabindupallanti | 0:5e96fed89c06 | 11 | '0' // r2 |
himabindupallanti | 0:5e96fed89c06 | 12 | // c0 c1 c2 |
himabindupallanti | 0:5e96fed89c06 | 13 | }; |
himabindupallanti | 0:5e96fed89c06 | 14 | |
himabindupallanti | 0:5e96fed89c06 | 15 | int32_t Index = -1; |
himabindupallanti | 0:5e96fed89c06 | 16 | int State; |
himabindupallanti | 0:5e96fed89c06 | 17 | |
himabindupallanti | 0:5e96fed89c06 | 18 | uint32_t cbAfterInput(uint32_t index) |
himabindupallanti | 0:5e96fed89c06 | 19 | { |
himabindupallanti | 0:5e96fed89c06 | 20 | Index = index; |
himabindupallanti | 0:5e96fed89c06 | 21 | return 0; |
himabindupallanti | 0:5e96fed89c06 | 22 | } |
himabindupallanti | 0:5e96fed89c06 | 23 | |
himabindupallanti | 0:5e96fed89c06 | 24 | int main() |
himabindupallanti | 0:5e96fed89c06 | 25 | { |
himabindupallanti | 0:5e96fed89c06 | 26 | PC.printf("I am Demo Keypad\r\n"); |
himabindupallanti | 0:5e96fed89c06 | 27 | |
himabindupallanti | 0:5e96fed89c06 | 28 | // r0 r1 r2 r3 c0 c1 c2 c3 |
himabindupallanti | 0:5e96fed89c06 | 29 | Keypad keypad(p21, p22, p23, p24, p25, p26, p27, p28); |
himabindupallanti | 0:5e96fed89c06 | 30 | keypad.attach(&cbAfterInput); |
himabindupallanti | 0:5e96fed89c06 | 31 | keypad.start(); // energize the columns c0-c3 of the keypad |
himabindupallanti | 0:5e96fed89c06 | 32 | |
himabindupallanti | 0:5e96fed89c06 | 33 | while (1) { |
himabindupallanti | 0:5e96fed89c06 | 34 | __wfi(); |
himabindupallanti | 0:5e96fed89c06 | 35 | if (Index > -1) { |
himabindupallanti | 0:5e96fed89c06 | 36 | PC.printf("Interrupted"); |
himabindupallanti | 0:5e96fed89c06 | 37 | PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); |
himabindupallanti | 0:5e96fed89c06 | 38 | Index = -1; |
himabindupallanti | 0:5e96fed89c06 | 39 | } |
himabindupallanti | 0:5e96fed89c06 | 40 | } |
himabindupallanti | 0:5e96fed89c06 | 41 | } |