Task 5.2.3 Solution

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Thu Sep 24 12:31:48 2015 +0000
Commit message:
Initial version 24-09-2015

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 277f12eec770 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 24 12:31:48 2015 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+
+//Global PWM object
+PwmOut pwmRed(D7);
+
+int T = 100;    //100uS
+volatile int Tmark = 0; //0us
+volatile int delta = 1; //1us
+
+//Timer
+Ticker t;
+
+//Function prototype 
+void doTwinkle();
+
+int main() {
+    
+    //Initial PWM state
+    pwmRed.period_us(T);
+    pwmRed.pulsewidth_us(Tmark);
+    
+    //Start timer
+    t.attach(doTwinkle, 0.01);
+    
+    while(1) {
+        sleep();
+        
+        //Update PWM
+        pwmRed.pulsewidth_us(Tmark);
+        
+        //printf("Tmark = %d\n", Tmark);    //Debug
+    }
+}
+
+//ISR for Timer
+void doTwinkle()
+{
+    //Update mark time
+    Tmark += delta;
+    
+    //Check bounds - and swap direction
+    if ((Tmark >= 99) || (Tmark <= 0)) {
+        delta = -delta;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 277f12eec770 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 24 12:31:48 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa
\ No newline at end of file