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 A3_1_Single_Timer
main.cpp@3:d90d04dce9f2, 2020-10-06 (annotated)
- Committer:
- markschwarzer
- Date:
- Tue Oct 06 15:04:26 2020 +0000
- Revision:
- 3:d90d04dce9f2
- Parent:
- 2:de9d94dc0454
final commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| slicht_instructor | 1:76d11e984b8d | 1 | #include "mbed.h" |
| slicht_instructor | 1:76d11e984b8d | 2 | Ticker tickerLED2; //creat ticker object |
| markschwarzer | 3:d90d04dce9f2 | 3 | Ticker tickerLED3; |
| slicht_instructor | 1:76d11e984b8d | 4 | DigitalOut LEDOut2(LED2); |
| markschwarzer | 3:d90d04dce9f2 | 5 | DigitalOut LEDOut3(LED3); |
| slicht_instructor | 0:5597320f2dba | 6 | |
| slicht_instructor | 1:76d11e984b8d | 7 | void changeLED2() //the function that will be called by the ticker object. |
| slicht_instructor | 1:76d11e984b8d | 8 | { |
| slicht_instructor | 1:76d11e984b8d | 9 | LEDOut2 = !LEDOut2; |
| slicht_instructor | 1:76d11e984b8d | 10 | } |
| markschwarzer | 3:d90d04dce9f2 | 11 | void changeLED3() //function called for other ticker object LED3 |
| markschwarzer | 3:d90d04dce9f2 | 12 | { |
| markschwarzer | 3:d90d04dce9f2 | 13 | LEDOut3 = !LEDOut3; |
| markschwarzer | 3:d90d04dce9f2 | 14 | } |
| slicht_instructor | 0:5597320f2dba | 15 | |
| slicht_instructor | 0:5597320f2dba | 16 | int main() |
| slicht_instructor | 0:5597320f2dba | 17 | { |
| slicht_instructor | 1:76d11e984b8d | 18 | tickerLED2.attach(&changeLED2,0.2); //the address of the function to call |
| slicht_instructor | 1:76d11e984b8d | 19 | //and the interval in seconds between |
| slicht_instructor | 1:76d11e984b8d | 20 | //calls to that function |
| markschwarzer | 3:d90d04dce9f2 | 21 | tickerLED3.attach(&changeLED3,0.8); //changing the interval in seconds for LED3 |
| slicht_instructor | 0:5597320f2dba | 22 | |
| slicht_instructor | 0:5597320f2dba | 23 | while(1) { |
| slicht_instructor | 1:76d11e984b8d | 24 | wait(0.1); |
| slicht_instructor | 1:76d11e984b8d | 25 | wait(0.1); |
| slicht_instructor | 1:76d11e984b8d | 26 | wait(0.1); |
| slicht_instructor | 1:76d11e984b8d | 27 | wait(0.1); |
| slicht_instructor | 1:76d11e984b8d | 28 | wait(0.1); |
| slicht_instructor | 1:76d11e984b8d | 29 | //the main loop is spinning every 500ms, but the LED needs to go faster! |
| slicht_instructor | 0:5597320f2dba | 30 | } //while |
| slicht_instructor | 0:5597320f2dba | 31 | } |