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.
main.cpp@3:f6547e1c1dfc, 2021-10-21 (annotated)
- Committer:
- mgimple
- Date:
- Thu Oct 21 13:43:27 2021 +0000
- Revision:
- 3:f6547e1c1dfc
- Parent:
- 1:76d11e984b8d
- Child:
- 4:90f9fff2e44e
LED 2 blinks on off 200ms; LED 3 blinks on off 300ms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
slicht_instructor | 1:76d11e984b8d | 1 | //Base code for modification for Assignment 3.2 |
slicht_instructor | 1:76d11e984b8d | 2 | //Blinks LED2 every 200ms using a single Ticker object. |
slicht_instructor | 0:5597320f2dba | 3 | //Created: S. Licht, 10/04/2020 |
slicht_instructor | 1:76d11e984b8d | 4 | #include "mbed.h" |
mgimple | 3:f6547e1c1dfc | 5 | Ticker tickerLED2; //create ticker object |
mgimple | 3:f6547e1c1dfc | 6 | Ticker tickerLED3; |
slicht_instructor | 1:76d11e984b8d | 7 | DigitalOut LEDOut2(LED2); |
mgimple | 3:f6547e1c1dfc | 8 | DigitalOut LEDOut3(LED3); |
slicht_instructor | 0:5597320f2dba | 9 | |
slicht_instructor | 1:76d11e984b8d | 10 | void changeLED2() //the function that will be called by the ticker object. |
slicht_instructor | 1:76d11e984b8d | 11 | { |
slicht_instructor | 1:76d11e984b8d | 12 | LEDOut2 = !LEDOut2; |
slicht_instructor | 1:76d11e984b8d | 13 | } |
slicht_instructor | 0:5597320f2dba | 14 | |
mgimple | 3:f6547e1c1dfc | 15 | void changeLED3() //the function that will be called by the ticker object. |
mgimple | 3:f6547e1c1dfc | 16 | { |
mgimple | 3:f6547e1c1dfc | 17 | LEDOut3 = !LEDOut3; |
mgimple | 3:f6547e1c1dfc | 18 | } |
mgimple | 3:f6547e1c1dfc | 19 | |
mgimple | 3:f6547e1c1dfc | 20 | |
slicht_instructor | 0:5597320f2dba | 21 | int main() |
slicht_instructor | 0:5597320f2dba | 22 | { |
slicht_instructor | 1:76d11e984b8d | 23 | tickerLED2.attach(&changeLED2,0.2); //the address of the function to call |
slicht_instructor | 1:76d11e984b8d | 24 | //and the interval in seconds between |
slicht_instructor | 1:76d11e984b8d | 25 | //calls to that function |
slicht_instructor | 0:5597320f2dba | 26 | |
mgimple | 3:f6547e1c1dfc | 27 | tickerLED3.attach(&changeLED3,0.3); |
mgimple | 3:f6547e1c1dfc | 28 | |
mgimple | 3:f6547e1c1dfc | 29 | |
slicht_instructor | 1:76d11e984b8d | 30 | //the main loop is spinning every 500ms, but the LED needs to go faster! |
mgimple | 3:f6547e1c1dfc | 31 | //while |
slicht_instructor | 0:5597320f2dba | 32 | } |