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.
Assignment3_1.cpp@2:4224d5ca4f2d, 2022-10-14 (annotated)
- Committer:
- michael_antonucci
- Date:
- Fri Oct 14 13:18:51 2022 +0000
- Revision:
- 2:4224d5ca4f2d
Working timer code. Grade This
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| michael_antonucci | 2:4224d5ca4f2d | 1 | //Code for Assignment 3.1 |
| michael_antonucci | 2:4224d5ca4f2d | 2 | //Blinks LED2 every 200ms and LED3 every 400ms using two Timer objects. |
| michael_antonucci | 2:4224d5ca4f2d | 3 | //Created: M. Antonucci 10/11/22(edited version of S. Licht's code) |
| michael_antonucci | 2:4224d5ca4f2d | 4 | |
| michael_antonucci | 2:4224d5ca4f2d | 5 | #include "mbed.h" |
| michael_antonucci | 2:4224d5ca4f2d | 6 | |
| michael_antonucci | 2:4224d5ca4f2d | 7 | Timer timerLED2; //creat timer object |
| michael_antonucci | 2:4224d5ca4f2d | 8 | Timer timerLED3; |
| michael_antonucci | 2:4224d5ca4f2d | 9 | DigitalOut LEDOut2(LED2); |
| michael_antonucci | 2:4224d5ca4f2d | 10 | DigitalOut LEDOut3(LED3); |
| michael_antonucci | 2:4224d5ca4f2d | 11 | |
| michael_antonucci | 2:4224d5ca4f2d | 12 | int main() |
| michael_antonucci | 2:4224d5ca4f2d | 13 | { |
| michael_antonucci | 2:4224d5ca4f2d | 14 | timerLED2.start(); //start timer counting on the LED2 timer |
| michael_antonucci | 2:4224d5ca4f2d | 15 | timerLED3.start(); //start timer counting on the LED3 timer |
| michael_antonucci | 2:4224d5ca4f2d | 16 | |
| michael_antonucci | 2:4224d5ca4f2d | 17 | while(1) { |
| michael_antonucci | 2:4224d5ca4f2d | 18 | if (timerLED2.read_ms()>=200) { //check to see if time has been exceeded |
| michael_antonucci | 2:4224d5ca4f2d | 19 | LEDOut2 = !LEDOut2; |
| michael_antonucci | 2:4224d5ca4f2d | 20 | timerLED2.reset(); //reset the timer2 back to zero |
| michael_antonucci | 2:4224d5ca4f2d | 21 | } //if timer |
| michael_antonucci | 2:4224d5ca4f2d | 22 | if (timerLED3.read_ms()>=400) { |
| michael_antonucci | 2:4224d5ca4f2d | 23 | LEDOut3 = !LEDOut3; |
| michael_antonucci | 2:4224d5ca4f2d | 24 | timerLED3.reset(); //reset the timer3 back to zero |
| michael_antonucci | 2:4224d5ca4f2d | 25 | } |
| michael_antonucci | 2:4224d5ca4f2d | 26 | //if you had other code that you wanted to execute faster, |
| michael_antonucci | 2:4224d5ca4f2d | 27 | //you could put it here! |
| michael_antonucci | 2:4224d5ca4f2d | 28 | |
| michael_antonucci | 2:4224d5ca4f2d | 29 | } //while |
| michael_antonucci | 2:4224d5ca4f2d | 30 | } |