Assignment3.1 code. Fully functional code. GRADE THIS

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Assignment3_1.cpp Source File

Assignment3_1.cpp

00001 //Code for Assignment 3.1
00002 //Blinks LED2 every 200ms and LED3 every 400ms using two Timer objects.
00003 //Created: M. Antonucci 10/11/22(edited version of S. Licht's code)
00004 
00005 #include "mbed.h"
00006 
00007 Timer timerLED2;  //creat timer object
00008 Timer timerLED3;
00009 DigitalOut LEDOut2(LED2);
00010 DigitalOut LEDOut3(LED3);
00011 
00012 int main()
00013 {
00014     timerLED2.start(); //start timer counting on the LED2 timer
00015     timerLED3.start(); //start timer counting on the LED3 timer
00016 
00017     while(1) {
00018         if (timerLED2.read_ms()>=200) { //check to see if time has been exceeded
00019             LEDOut2 = !LEDOut2;
00020             timerLED2.reset();  //reset the timer2 back to zero
00021         }  //if timer
00022         if (timerLED3.read_ms()>=400) {
00023             LEDOut3 = !LEDOut3;
00024             timerLED3.reset();  //reset the timer3 back to zero
00025         }
00026         //if you had other code that you wanted to execute faster,
00027         //you could put it here!
00028         
00029     } //while
00030 }