Gerardo Carmona
/
info_interrupts
main.cpp@0:d10d1e4ecd6b, 2014-05-09 (annotated)
- Committer:
- gcarmonar
- Date:
- Fri May 09 15:34:11 2014 +0000
- Revision:
- 0:d10d1e4ecd6b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gcarmonar | 0:d10d1e4ecd6b | 1 | /* |
gcarmonar | 0:d10d1e4ecd6b | 2 | On KL25Z interrupts only works on ports A and D |
gcarmonar | 0:d10d1e4ecd6b | 3 | Options are: raise and fall |
gcarmonar | 0:d10d1e4ecd6b | 4 | */ |
gcarmonar | 0:d10d1e4ecd6b | 5 | |
gcarmonar | 0:d10d1e4ecd6b | 6 | #include "mbed.h" |
gcarmonar | 0:d10d1e4ecd6b | 7 | |
gcarmonar | 0:d10d1e4ecd6b | 8 | InterruptIn button(PTD4); //D3 |
gcarmonar | 0:d10d1e4ecd6b | 9 | DigitalOut led(LED1); |
gcarmonar | 0:d10d1e4ecd6b | 10 | DigitalOut flash(LED3); |
gcarmonar | 0:d10d1e4ecd6b | 11 | |
gcarmonar | 0:d10d1e4ecd6b | 12 | |
gcarmonar | 0:d10d1e4ecd6b | 13 | void flip(); |
gcarmonar | 0:d10d1e4ecd6b | 14 | |
gcarmonar | 0:d10d1e4ecd6b | 15 | int main() { |
gcarmonar | 0:d10d1e4ecd6b | 16 | button.rise(&flip); // attach the address of the flip function to the rising edge |
gcarmonar | 0:d10d1e4ecd6b | 17 | |
gcarmonar | 0:d10d1e4ecd6b | 18 | while(1) { // wait around, interrupts will interrupt this! |
gcarmonar | 0:d10d1e4ecd6b | 19 | flash = !flash; |
gcarmonar | 0:d10d1e4ecd6b | 20 | wait(0.25); |
gcarmonar | 0:d10d1e4ecd6b | 21 | } |
gcarmonar | 0:d10d1e4ecd6b | 22 | } |
gcarmonar | 0:d10d1e4ecd6b | 23 | |
gcarmonar | 0:d10d1e4ecd6b | 24 | void flip() { |
gcarmonar | 0:d10d1e4ecd6b | 25 | led = !led; |
gcarmonar | 0:d10d1e4ecd6b | 26 | } |