Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Amaldi_4_Exercise_LED-Button_Interrupt by
main.cpp@0:7d38be0bc9c1, 2017-07-06 (annotated)
- Committer:
- bcostm
- Date:
- Thu Jul 06 08:26:28 2017 +0000
- Revision:
- 0:7d38be0bc9c1
Initial version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bcostm | 0:7d38be0bc9c1 | 1 | #include "mbed.h" |
| bcostm | 0:7d38be0bc9c1 | 2 | |
| bcostm | 0:7d38be0bc9c1 | 3 | InterruptIn button(USER_BUTTON); |
| bcostm | 0:7d38be0bc9c1 | 4 | |
| bcostm | 0:7d38be0bc9c1 | 5 | DigitalOut led(LED1); |
| bcostm | 0:7d38be0bc9c1 | 6 | |
| bcostm | 0:7d38be0bc9c1 | 7 | double delay = 0.5; // 500 ms |
| bcostm | 0:7d38be0bc9c1 | 8 | |
| bcostm | 0:7d38be0bc9c1 | 9 | void pressed() |
| bcostm | 0:7d38be0bc9c1 | 10 | { |
| bcostm | 0:7d38be0bc9c1 | 11 | delay = 0.1; // 100 ms |
| bcostm | 0:7d38be0bc9c1 | 12 | } |
| bcostm | 0:7d38be0bc9c1 | 13 | |
| bcostm | 0:7d38be0bc9c1 | 14 | void released() |
| bcostm | 0:7d38be0bc9c1 | 15 | { |
| bcostm | 0:7d38be0bc9c1 | 16 | delay = 0.5; // 500 ms |
| bcostm | 0:7d38be0bc9c1 | 17 | } |
| bcostm | 0:7d38be0bc9c1 | 18 | |
| bcostm | 0:7d38be0bc9c1 | 19 | int main() |
| bcostm | 0:7d38be0bc9c1 | 20 | { |
| bcostm | 0:7d38be0bc9c1 | 21 | // Assign functions to button |
| bcostm | 0:7d38be0bc9c1 | 22 | button.fall(&pressed); |
| bcostm | 0:7d38be0bc9c1 | 23 | button.rise(&released); |
| bcostm | 0:7d38be0bc9c1 | 24 | |
| bcostm | 0:7d38be0bc9c1 | 25 | while (1) { |
| bcostm | 0:7d38be0bc9c1 | 26 | led = !led; |
| bcostm | 0:7d38be0bc9c1 | 27 | wait(delay); |
| bcostm | 0:7d38be0bc9c1 | 28 | } |
| bcostm | 0:7d38be0bc9c1 | 29 | } |
