John Kemp
/
interruptin_test
Oddness with multiple \'InterruptIn\'s
main.cpp@0:ba602786a4c1, 2011-03-30 (annotated)
- Committer:
- Kemp
- Date:
- Wed Mar 30 15:53:03 2011 +0000
- Revision:
- 0:ba602786a4c1
- Child:
- 1:0228f6b60488
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kemp | 0:ba602786a4c1 | 1 | #include "mbed.h" |
Kemp | 0:ba602786a4c1 | 2 | |
Kemp | 0:ba602786a4c1 | 3 | Serial pc(USBTX, USBRX); |
Kemp | 0:ba602786a4c1 | 4 | |
Kemp | 0:ba602786a4c1 | 5 | InterruptIn button1(p12); |
Kemp | 0:ba602786a4c1 | 6 | InterruptIn button2(p11); |
Kemp | 0:ba602786a4c1 | 7 | InterruptIn button3(p10); |
Kemp | 0:ba602786a4c1 | 8 | |
Kemp | 0:ba602786a4c1 | 9 | Timeout button1_debounce; |
Kemp | 0:ba602786a4c1 | 10 | Timeout button2_debounce; |
Kemp | 0:ba602786a4c1 | 11 | Timeout button3_debounce; |
Kemp | 0:ba602786a4c1 | 12 | |
Kemp | 0:ba602786a4c1 | 13 | void button1_pressed() {pc.printf("Button 1");} |
Kemp | 0:ba602786a4c1 | 14 | void button2_pressed() {pc.printf("Button 2");} |
Kemp | 0:ba602786a4c1 | 15 | void button3_pressed() {pc.printf("Button 3");} |
Kemp | 0:ba602786a4c1 | 16 | |
Kemp | 0:ba602786a4c1 | 17 | void button1_press() {button1_debounce.attach(button1_pressed, 0.3);} |
Kemp | 0:ba602786a4c1 | 18 | void button2_press() {button2_debounce.attach(button2_pressed, 0.3);} |
Kemp | 0:ba602786a4c1 | 19 | void button3_press() {button3_debounce.attach(button3_pressed, 0.3);} |
Kemp | 0:ba602786a4c1 | 20 | |
Kemp | 0:ba602786a4c1 | 21 | |
Kemp | 0:ba602786a4c1 | 22 | int main() |
Kemp | 0:ba602786a4c1 | 23 | { |
Kemp | 0:ba602786a4c1 | 24 | // Set up buttons |
Kemp | 0:ba602786a4c1 | 25 | button1.mode(PullDown); |
Kemp | 0:ba602786a4c1 | 26 | button1.rise(&button1_press); |
Kemp | 0:ba602786a4c1 | 27 | |
Kemp | 0:ba602786a4c1 | 28 | button2.mode(PullDown); |
Kemp | 0:ba602786a4c1 | 29 | button2.rise(&button2_press); |
Kemp | 0:ba602786a4c1 | 30 | |
Kemp | 0:ba602786a4c1 | 31 | button3.mode(PullDown); |
Kemp | 0:ba602786a4c1 | 32 | button3.rise(&button3_press); |
Kemp | 0:ba602786a4c1 | 33 | |
Kemp | 0:ba602786a4c1 | 34 | while (1); |
Kemp | 0:ba602786a4c1 | 35 | } |