István Cserny
/
Lab04_button_interrupt
main.cpp@0:694507d2d42b, 2021-11-16 (annotated)
- Committer:
- cspista
- Date:
- Tue Nov 16 12:04:51 2021 +0000
- Revision:
- 0:694507d2d42b
Final version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cspista | 0:694507d2d42b | 1 | #include "mbed.h" |
cspista | 0:694507d2d42b | 2 | |
cspista | 0:694507d2d42b | 3 | InterruptIn button(BUTTON1); // Pusbutton input (PC_13) |
cspista | 0:694507d2d42b | 4 | DigitalOut led(LED1); // LED output (PA_5) |
cspista | 0:694507d2d42b | 5 | |
cspista | 0:694507d2d42b | 6 | void button_pressed() { |
cspista | 0:694507d2d42b | 7 | led = !led; // LED state changed at every button press |
cspista | 0:694507d2d42b | 8 | } |
cspista | 0:694507d2d42b | 9 | |
cspista | 0:694507d2d42b | 10 | int main() { |
cspista | 0:694507d2d42b | 11 | button.mode(PullUp); // Enable internal pullup |
cspista | 0:694507d2d42b | 12 | button.fall(&button_pressed); // Attach function to falling edge |
cspista | 0:694507d2d42b | 13 | while (true) { |
cspista | 0:694507d2d42b | 14 | wait(0.2f); // Nothing to do. Just wait |
cspista | 0:694507d2d42b | 15 | } |
cspista | 0:694507d2d42b | 16 | } |