![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Polling
main.cpp@0:ecb474821d8f, 2015-02-02 (annotated)
- Committer:
- sandeshkumar
- Date:
- Mon Feb 02 21:36:00 2015 +0000
- Revision:
- 0:ecb474821d8f
Initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandeshkumar | 0:ecb474821d8f | 1 | #include "mbed.h" |
sandeshkumar | 0:ecb474821d8f | 2 | |
sandeshkumar | 0:ecb474821d8f | 3 | InterruptIn pin22(p22); |
sandeshkumar | 0:ecb474821d8f | 4 | InterruptIn pin23(p23); |
sandeshkumar | 0:ecb474821d8f | 5 | DigitalOut led1(LED1); |
sandeshkumar | 0:ecb474821d8f | 6 | DigitalOut led2(LED2); |
sandeshkumar | 0:ecb474821d8f | 7 | |
sandeshkumar | 0:ecb474821d8f | 8 | DigitalOut pin17(p17); |
sandeshkumar | 0:ecb474821d8f | 9 | DigitalOut pin18(p18); |
sandeshkumar | 0:ecb474821d8f | 10 | DigitalOut pin19(p19); |
sandeshkumar | 0:ecb474821d8f | 11 | DigitalOut pin20(p20); |
sandeshkumar | 0:ecb474821d8f | 12 | |
sandeshkumar | 0:ecb474821d8f | 13 | void riseLed1() { |
sandeshkumar | 0:ecb474821d8f | 14 | led1 = 1; |
sandeshkumar | 0:ecb474821d8f | 15 | } |
sandeshkumar | 0:ecb474821d8f | 16 | |
sandeshkumar | 0:ecb474821d8f | 17 | void fallLed1() { |
sandeshkumar | 0:ecb474821d8f | 18 | led1 = 0; |
sandeshkumar | 0:ecb474821d8f | 19 | } |
sandeshkumar | 0:ecb474821d8f | 20 | |
sandeshkumar | 0:ecb474821d8f | 21 | void riseLed2() { |
sandeshkumar | 0:ecb474821d8f | 22 | led2 = 1; |
sandeshkumar | 0:ecb474821d8f | 23 | } |
sandeshkumar | 0:ecb474821d8f | 24 | |
sandeshkumar | 0:ecb474821d8f | 25 | void fallLed2() { |
sandeshkumar | 0:ecb474821d8f | 26 | led2 = 0; |
sandeshkumar | 0:ecb474821d8f | 27 | } |
sandeshkumar | 0:ecb474821d8f | 28 | |
sandeshkumar | 0:ecb474821d8f | 29 | int main() { |
sandeshkumar | 0:ecb474821d8f | 30 | pin17 = 1; |
sandeshkumar | 0:ecb474821d8f | 31 | pin18 = 1; |
sandeshkumar | 0:ecb474821d8f | 32 | pin19 = 1; |
sandeshkumar | 0:ecb474821d8f | 33 | pin20 = 1; |
sandeshkumar | 0:ecb474821d8f | 34 | |
sandeshkumar | 0:ecb474821d8f | 35 | pin22.rise(&riseLed1); // attach the address of the flip function to the rising edge |
sandeshkumar | 0:ecb474821d8f | 36 | pin23.rise(&riseLed2); // attach the address of the flip function to the rising edge |
sandeshkumar | 0:ecb474821d8f | 37 | pin22.fall(&fallLed1); |
sandeshkumar | 0:ecb474821d8f | 38 | pin23.fall(&fallLed2); |
sandeshkumar | 0:ecb474821d8f | 39 | while(1) { // wait around, interrupts will interrupt this! |
sandeshkumar | 0:ecb474821d8f | 40 | wait(0.1); |
sandeshkumar | 0:ecb474821d8f | 41 | } |
sandeshkumar | 0:ecb474821d8f | 42 | |
sandeshkumar | 0:ecb474821d8f | 43 | |
sandeshkumar | 0:ecb474821d8f | 44 | } |
sandeshkumar | 0:ecb474821d8f | 45 | |
sandeshkumar | 0:ecb474821d8f | 46 | /*#include "mbed.h" |
sandeshkumar | 0:ecb474821d8f | 47 | #include "keypad.h" |
sandeshkumar | 0:ecb474821d8f | 48 | |
sandeshkumar | 0:ecb474821d8f | 49 | // Define your own keypad values |
sandeshkumar | 0:ecb474821d8f | 50 | char Keytable[] = { '1', '2', '3', 'A', |
sandeshkumar | 0:ecb474821d8f | 51 | '4', '5', '6', 'B', |
sandeshkumar | 0:ecb474821d8f | 52 | '7', '8', '9', 'C', |
sandeshkumar | 0:ecb474821d8f | 53 | '*', '0', '#', 'D' |
sandeshkumar | 0:ecb474821d8f | 54 | }; |
sandeshkumar | 0:ecb474821d8f | 55 | |
sandeshkumar | 0:ecb474821d8f | 56 | uint32_t cbAfterInput(uint32_t index) { |
sandeshkumar | 0:ecb474821d8f | 57 | printf("Index:%d => Key:%c\n", key, Keytable[index]); |
sandeshkumar | 0:ecb474821d8f | 58 | return 0; |
sandeshkumar | 0:ecb474821d8f | 59 | } |
sandeshkumar | 0:ecb474821d8f | 60 | |
sandeshkumar | 0:ecb474821d8f | 61 | int main() { |
sandeshkumar | 0:ecb474821d8f | 62 | Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24); |
sandeshkumar | 0:ecb474821d8f | 63 | keypad.CallAfterInput(&cbAfterInput); |
sandeshkumar | 0:ecb474821d8f | 64 | keypad.Start(); |
sandeshkumar | 0:ecb474821d8f | 65 | |
sandeshkumar | 0:ecb474821d8f | 66 | while (1) { |
sandeshkumar | 0:ecb474821d8f | 67 | wait_ms(100); |
sandeshkumar | 0:ecb474821d8f | 68 | } |
sandeshkumar | 0:ecb474821d8f | 69 | }*/ |