hi
Dependencies: DebouncedInterrupt mbed
Fork of InterruptIn_HelloWorld by
main.cpp@1:da4614736799, 2016-09-29 (annotated)
- Committer:
- erroras
- Date:
- Thu Sep 29 22:19:13 2016 +0000
- Revision:
- 1:da4614736799
- Parent:
- 0:7a20a6aa1f5e
or a class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:7a20a6aa1f5e | 1 | #include "mbed.h" |
erroras | 1:da4614736799 | 2 | #include "DebouncedInterrupt.h" |
erroras | 1:da4614736799 | 3 | |
erroras | 1:da4614736799 | 4 | DigitalOut columnoneout ( D5 ); // pin 3 on keypad |
erroras | 1:da4614736799 | 5 | DigitalOut columntwoout ( D4 ); // pin 1 on keypad |
erroras | 1:da4614736799 | 6 | DigitalOut columnthreeout ( D2 ); // pin 5 on keypad |
erroras | 1:da4614736799 | 7 | |
erroras | 1:da4614736799 | 8 | //InterruptIn button(USER_BUTTON); //set user blue button as interrupt |
erroras | 1:da4614736799 | 9 | DebouncedInterrupt rowOne(D12); |
erroras | 1:da4614736799 | 10 | DebouncedInterrupt rowTwo(D11); |
erroras | 1:da4614736799 | 11 | DebouncedInterrupt rowThree(D7); |
erroras | 1:da4614736799 | 12 | DebouncedInterrupt rowFour(D6); |
erroras | 1:da4614736799 | 13 | |
erroras | 1:da4614736799 | 14 | void InterrRowOne() { //this is a function (instructions) that will happen when interrupt happens |
erroras | 1:da4614736799 | 15 | if ( columnoneout == 1){ |
erroras | 1:da4614736799 | 16 | printf("3\n");} |
erroras | 1:da4614736799 | 17 | if ( columntwoout == 1){ |
erroras | 1:da4614736799 | 18 | printf("1\n");} |
erroras | 1:da4614736799 | 19 | if ( columnthreeout == 1){ |
erroras | 1:da4614736799 | 20 | printf("2\n");} } |
erroras | 1:da4614736799 | 21 | |
erroras | 1:da4614736799 | 22 | void InterrRowTwo() { //this is a function (instructions) that will happen when interrupt happens |
erroras | 1:da4614736799 | 23 | if ( columnoneout == 1){ |
erroras | 1:da4614736799 | 24 | printf("6\n");} |
erroras | 1:da4614736799 | 25 | if ( columntwoout == 1){ |
erroras | 1:da4614736799 | 26 | printf("4\n");} |
erroras | 1:da4614736799 | 27 | if ( columnthreeout == 1){ |
erroras | 1:da4614736799 | 28 | printf("5\n");} } |
erroras | 1:da4614736799 | 29 | |
erroras | 1:da4614736799 | 30 | void InterrRowThree() { //this is a function (instructions) that will happen when interrupt happens |
erroras | 1:da4614736799 | 31 | if ( columnoneout == 1){ |
erroras | 1:da4614736799 | 32 | printf("9\n");} |
erroras | 1:da4614736799 | 33 | if ( columntwoout == 1){ |
erroras | 1:da4614736799 | 34 | printf("7\n");} |
erroras | 1:da4614736799 | 35 | if ( columnthreeout == 1){ |
erroras | 1:da4614736799 | 36 | printf("8\n");} } |
erroras | 1:da4614736799 | 37 | |
erroras | 1:da4614736799 | 38 | void InterrRowFour() { //this is a function (instructions) that will happen when interrupt happens |
erroras | 1:da4614736799 | 39 | if ( columnoneout == 1){ |
erroras | 1:da4614736799 | 40 | printf("#\n");} |
erroras | 1:da4614736799 | 41 | if ( columntwoout == 1){ |
erroras | 1:da4614736799 | 42 | printf("*\n");} |
erroras | 1:da4614736799 | 43 | if ( columnthreeout == 1){ |
erroras | 1:da4614736799 | 44 | printf("0\n");} } |
mbed_official | 0:7a20a6aa1f5e | 45 | |
mbed_official | 0:7a20a6aa1f5e | 46 | int main() { |
erroras | 1:da4614736799 | 47 | |
erroras | 1:da4614736799 | 48 | // Will immediatly call function and ignore other interrupts until timeout |
erroras | 1:da4614736799 | 49 | rowOne.attach(&InterrRowOne, IRQ_FALL, 100, false); |
erroras | 1:da4614736799 | 50 | rowTwo.attach(&InterrRowTwo, IRQ_FALL, 100, false); |
erroras | 1:da4614736799 | 51 | rowThree.attach(&InterrRowThree, IRQ_FALL, 100, false); |
erroras | 1:da4614736799 | 52 | rowFour.attach(&InterrRowFour, IRQ_FALL, 100, false); |
erroras | 1:da4614736799 | 53 | |
mbed_official | 0:7a20a6aa1f5e | 54 | while(1) { // wait around, interrupts will interrupt this! |
erroras | 1:da4614736799 | 55 | |
erroras | 1:da4614736799 | 56 | //alternate pulses |
erroras | 1:da4614736799 | 57 | columnoneout = 1; |
erroras | 1:da4614736799 | 58 | wait (0.01); |
erroras | 1:da4614736799 | 59 | columnoneout = 0; |
erroras | 1:da4614736799 | 60 | columntwoout = 1; |
erroras | 1:da4614736799 | 61 | wait (0.01); |
erroras | 1:da4614736799 | 62 | columntwoout = 0; |
erroras | 1:da4614736799 | 63 | columnthreeout = 1; |
erroras | 1:da4614736799 | 64 | wait (0.01); |
erroras | 1:da4614736799 | 65 | columnthreeout = 0; |
erroras | 1:da4614736799 | 66 | } |
erroras | 1:da4614736799 | 67 | } |