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 FTF2014_lab2_complete by
main.cpp@0:3561cbaefc3d, 2014-04-03 (annotated)
- Committer:
- Kojto
- Date:
- Thu Apr 03 08:58:46 2014 +0000
- Revision:
- 0:3561cbaefc3d
initial version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Kojto | 0:3561cbaefc3d | 1 | #include "mbed.h" |
| Kojto | 0:3561cbaefc3d | 2 | |
| Kojto | 0:3561cbaefc3d | 3 | DigitalOut led_red(LED_RED); |
| Kojto | 0:3561cbaefc3d | 4 | InterruptIn sw2(SW2); |
| Kojto | 0:3561cbaefc3d | 5 | Ticker ticker; |
| Kojto | 0:3561cbaefc3d | 6 | float interval; |
| Kojto | 0:3561cbaefc3d | 7 | |
| Kojto | 0:3561cbaefc3d | 8 | void led_toggle(void) |
| Kojto | 0:3561cbaefc3d | 9 | { |
| Kojto | 0:3561cbaefc3d | 10 | led_red = !led_red; |
| Kojto | 0:3561cbaefc3d | 11 | } |
| Kojto | 0:3561cbaefc3d | 12 | |
| Kojto | 0:3561cbaefc3d | 13 | void sw2_release(void) |
| Kojto | 0:3561cbaefc3d | 14 | { |
| Kojto | 0:3561cbaefc3d | 15 | printf("On-board button SW2 was released.\n"); |
| Kojto | 0:3561cbaefc3d | 16 | } |
| Kojto | 0:3561cbaefc3d | 17 | |
| Kojto | 0:3561cbaefc3d | 18 | void sw2_press(void) |
| Kojto | 0:3561cbaefc3d | 19 | { |
| Kojto | 0:3561cbaefc3d | 20 | printf("On-board button SW2 was pressed.\n"); |
| Kojto | 0:3561cbaefc3d | 21 | interval -= 0.1f; |
| Kojto | 0:3561cbaefc3d | 22 | ticker.detach(); |
| Kojto | 0:3561cbaefc3d | 23 | ticker.attach(&led_toggle, interval); |
| Kojto | 0:3561cbaefc3d | 24 | printf("LED toogle interval was set to: %f \n", interval); |
| Kojto | 0:3561cbaefc3d | 25 | if (interval < 0.5f) { |
| Kojto | 0:3561cbaefc3d | 26 | interval = 1.1f; |
| Kojto | 0:3561cbaefc3d | 27 | } |
| Kojto | 0:3561cbaefc3d | 28 | } |
| Kojto | 0:3561cbaefc3d | 29 | |
| Kojto | 0:3561cbaefc3d | 30 | int main() |
| Kojto | 0:3561cbaefc3d | 31 | { |
| Kojto | 0:3561cbaefc3d | 32 | interval = 1.0f; |
| Kojto | 0:3561cbaefc3d | 33 | sw2.rise(&sw2_release); |
| Kojto | 0:3561cbaefc3d | 34 | sw2.fall(&sw2_press); |
| Kojto | 0:3561cbaefc3d | 35 | ticker.attach(&led_toggle, interval); |
| Kojto | 0:3561cbaefc3d | 36 | while (true) { |
| Kojto | 0:3561cbaefc3d | 37 | } |
| Kojto | 0:3561cbaefc3d | 38 | } |
