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@2:427bf460dd91, 2021-10-15 (annotated)
- Committer:
- jmclaughlin
- Date:
- Fri Oct 15 01:50:47 2021 +0000
- Revision:
- 2:427bf460dd91
- Parent:
- 1:3cadb8807520
Code revised from Lichts to have multiple timers triggering LED2 and LED3 at 200ms and 400ms, respectively
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmclaughlin | 2:427bf460dd91 | 1 | /* |
jmclaughlin | 2:427bf460dd91 | 2 | Author: Jessica McLaughlin, revised from Stephen Licht |
jmclaughlin | 2:427bf460dd91 | 3 | Last Modified: 10/14/2021 |
jmclaughlin | 2:427bf460dd91 | 4 | Assignment: Multiple Timers, A2 Pt. 2 |
jmclaughlin | 2:427bf460dd91 | 5 | */ |
slicht_instructor | 0:5597320f2dba | 6 | |
slicht_instructor | 0:5597320f2dba | 7 | #include "mbed.h" |
slicht_instructor | 0:5597320f2dba | 8 | |
jmclaughlin | 2:427bf460dd91 | 9 | Timer timerLED2; //create timer object |
jmclaughlin | 2:427bf460dd91 | 10 | Timer timerLED3; |
slicht_instructor | 0:5597320f2dba | 11 | DigitalOut LEDOut2(LED2); |
jmclaughlin | 2:427bf460dd91 | 12 | DigitalOut LEDOut3(LED3); |
slicht_instructor | 0:5597320f2dba | 13 | |
slicht_instructor | 0:5597320f2dba | 14 | int main() |
slicht_instructor | 0:5597320f2dba | 15 | { |
slicht_instructor | 0:5597320f2dba | 16 | timerLED2.start(); //start timer counting |
jmclaughlin | 2:427bf460dd91 | 17 | timerLED3.start(); |
slicht_instructor | 0:5597320f2dba | 18 | |
slicht_instructor | 0:5597320f2dba | 19 | while(1) { |
slicht_instructor | 0:5597320f2dba | 20 | if (timerLED2.read_ms()>=200) { //check to see if time has been exceeded |
slicht_instructor | 0:5597320f2dba | 21 | LEDOut2 = !LEDOut2; |
slicht_instructor | 0:5597320f2dba | 22 | timerLED2.reset(); //reset the timer back to zero |
jmclaughlin | 2:427bf460dd91 | 23 | } |
jmclaughlin | 2:427bf460dd91 | 24 | if (timerLED3.read_ms()>=400) { //if exceeds on for 400ms |
jmclaughlin | 2:427bf460dd91 | 25 | LEDOut3 = !LEDOut3; |
jmclaughlin | 2:427bf460dd91 | 26 | timerLED3.reset(); |
jmclaughlin | 2:427bf460dd91 | 27 | } |
slicht_instructor | 0:5597320f2dba | 28 | } //while |
jmclaughlin | 2:427bf460dd91 | 29 | } |