![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
PErform interrupt ISR upon prompt over an existing sequence.
main.cpp@0:670c8100830e, 2020-07-31 (annotated)
- Committer:
- saltire78
- Date:
- Fri Jul 31 12:47:28 2020 +0000
- Revision:
- 0:670c8100830e
online posting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
saltire78 | 0:670c8100830e | 1 | #include"mbed.h" |
saltire78 | 0:670c8100830e | 2 | #include "C12832.h" |
saltire78 | 0:670c8100830e | 3 | |
saltire78 | 0:670c8100830e | 4 | InterruptIn joystickcenter(p14); |
saltire78 | 0:670c8100830e | 5 | InterruptIn button(p9); |
saltire78 | 0:670c8100830e | 6 | DigitalOut led(LED1); |
saltire78 | 0:670c8100830e | 7 | DigitalOut flash(LED4); |
saltire78 | 0:670c8100830e | 8 | C12832 lcd(p5, p7, p6, p8, p11); |
saltire78 | 0:670c8100830e | 9 | int state; |
saltire78 | 0:670c8100830e | 10 | int i=0; |
saltire78 | 0:670c8100830e | 11 | |
saltire78 | 0:670c8100830e | 12 | void flip(){ |
saltire78 | 0:670c8100830e | 13 | led=!led; // toggles the led when the joystick button is pressed. |
saltire78 | 0:670c8100830e | 14 | state= 1; |
saltire78 | 0:670c8100830e | 15 | } |
saltire78 | 0:670c8100830e | 16 | |
saltire78 | 0:670c8100830e | 17 | int main(){ |
saltire78 | 0:670c8100830e | 18 | joystickcenter.rise(&flip); //attach the function address to the rising edge |
saltire78 | 0:670c8100830e | 19 | button.mode(PullUp); // With this, no external pullup resistor needed |
saltire78 | 0:670c8100830e | 20 | button.rise(&flip); // attach the function address to the rising edge |
saltire78 | 0:670c8100830e | 21 | |
saltire78 | 0:670c8100830e | 22 | while(1){ //wait around,interrupts will interrupt this! |
saltire78 | 0:670c8100830e | 23 | if (state == 1){ |
saltire78 | 0:670c8100830e | 24 | i++; |
saltire78 | 0:670c8100830e | 25 | lcd.locate(0,0); |
saltire78 | 0:670c8100830e | 26 | lcd.printf("Interrupt Activated x %d", i); |
saltire78 | 0:670c8100830e | 27 | state = 0; |
saltire78 | 0:670c8100830e | 28 | } |
saltire78 | 0:670c8100830e | 29 | else |
saltire78 | 0:670c8100830e | 30 | { |
saltire78 | 0:670c8100830e | 31 | flash=!flash; // turns LED4 on ifoff, off if on |
saltire78 | 0:670c8100830e | 32 | wait(0.25); // the instruction to wait for a quarter-second |
saltire78 | 0:670c8100830e | 33 | } |
saltire78 | 0:670c8100830e | 34 | } |
saltire78 | 0:670c8100830e | 35 | } |