Nostradamus X
/
keypad
try1 with keypad
keyo.cpp@5:90075e5fa9fd, 2017-11-07 (annotated)
- Committer:
- nostradamus2x
- Date:
- Tue Nov 07 07:43:05 2017 +0000
- Revision:
- 5:90075e5fa9fd
- Parent:
- 4:4c7fb6a870bf
Added the password updation using mod function.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nostradamus2x | 0:5151ad0261b3 | 1 | #include "mbed.h" |
nostradamus2x | 0:5151ad0261b3 | 2 | #include "Keypad.h" |
nostradamus2x | 0:5151ad0261b3 | 3 | |
nostradamus2x | 0:5151ad0261b3 | 4 | // Define your own keypad values |
nostradamus2x | 0:5151ad0261b3 | 5 | char Keytable[] = { '1', '2', '3', 'A', // r0 |
nostradamus2x | 0:5151ad0261b3 | 6 | '4', '5', '6', 'B', // r1 |
nostradamus2x | 0:5151ad0261b3 | 7 | '7', '8', '9', 'C', // r2 |
nostradamus2x | 0:5151ad0261b3 | 8 | '*', '0', '#', 'D', // r3 |
nostradamus2x | 0:5151ad0261b3 | 9 | }; |
nostradamus2x | 3:74062f7daedd | 10 | // c0 c1 c2 c3 |
nostradamus2x | 0:5151ad0261b3 | 11 | |
nostradamus2x | 0:5151ad0261b3 | 12 | uint32_t Index; |
nostradamus2x | 3:74062f7daedd | 13 | uint32_t pass = 1234,check=1,modc=1000; //password is 1234, modc is current val of mod. the value will be 10^(n-1). n is no of digits of pass |
nostradamus2x | 3:74062f7daedd | 14 | DigitalOut led1(LED_BLUE); |
nostradamus2x | 3:74062f7daedd | 15 | DigitalOut led2(LED_GREEN); |
nostradamus2x | 3:74062f7daedd | 16 | DigitalOut led3(LED_RED); |
nostradamus2x | 3:74062f7daedd | 17 | |
nostradamus2x | 0:5151ad0261b3 | 18 | uint32_t cbAfterInput(uint32_t index) { |
nostradamus2x | 0:5151ad0261b3 | 19 | Index = index; |
nostradamus2x | 3:74062f7daedd | 20 | led1=!led1; |
nostradamus2x | 3:74062f7daedd | 21 | if(check == 1) |
nostradamus2x | 3:74062f7daedd | 22 | if(pass/modc == Index) |
nostradamus2x | 3:74062f7daedd | 23 | { check = 1; |
nostradamus2x | 3:74062f7daedd | 24 | modc=modc/10; |
nostradamus2x | 3:74062f7daedd | 25 | } |
nostradamus2x | 4:4c7fb6a870bf | 26 | else check =0; |
nostradamus2x | 4:4c7fb6a870bf | 27 | else check =0; |
nostradamus2x | 3:74062f7daedd | 28 | |
nostradamus2x | 3:74062f7daedd | 29 | if(modc==0) |
nostradamus2x | 3:74062f7daedd | 30 | if(check == 1) led2=!led2; |
nostradamus2x | 3:74062f7daedd | 31 | else led3=!led3; |
nostradamus2x | 3:74062f7daedd | 32 | else; |
nostradamus2x | 5:90075e5fa9fd | 33 | pass=pass%10; |
nostradamus2x | 3:74062f7daedd | 34 | return 0; |
nostradamus2x | 0:5151ad0261b3 | 35 | } |
nostradamus2x | 0:5151ad0261b3 | 36 | |
nostradamus2x | 0:5151ad0261b3 | 37 | int main() { |
nostradamus2x | 1:a045dce72999 | 38 | // r0 r1 r2 r3 c0 c1 c2 c3 |
nostradamus2x | 1:a045dce72999 | 39 | Keypad keypad(PTE5, PTE4, PTE3, PTE2, PTB11, PTB10, PTB9, NC); |
nostradamus2x | 0:5151ad0261b3 | 40 | keypad.attach(&cbAfterInput); |
nostradamus2x | 0:5151ad0261b3 | 41 | keypad.start(); // energize the keypad via c0-c3 |
nostradamus2x | 3:74062f7daedd | 42 | //PwmOut r(LED_RED); //for checking |
nostradamus2x | 1:a045dce72999 | 43 | |
nostradamus2x | 0:5151ad0261b3 | 44 | while (1) { |
nostradamus2x | 0:5151ad0261b3 | 45 | __wfi(); |
nostradamus2x | 0:5151ad0261b3 | 46 | printf("Interrupted\r\n"); |
nostradamus2x | 0:5151ad0261b3 | 47 | printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); |
nostradamus2x | 0:5151ad0261b3 | 48 | } |
nostradamus2x | 0:5151ad0261b3 | 49 | } |