PwmOut Hello World

Fork of PwmOut_HelloWorld by Mbed

Note

Set the cycle time first, then set the duty cycle using either a relative time period via the write() function or an absolute time period using the pulsewidth() function.

Revision:
1:5160ea45399b
Parent:
0:50d2b9c62765
--- a/main.cpp	Tue Feb 12 15:10:53 2013 +0000
+++ b/main.cpp	Sun Sep 21 06:39:30 2014 +0000
@@ -1,12 +1,12 @@
 #include "mbed.h"
- 
+
 PwmOut led(LED1);
- 
+
 int main() {
-    while(1) {
-        for(float p = 0.0f; p < 1.0f; p += 0.1f) {
-            led = p;
-            wait(0.1);
-        }
-    }
+    // specify period first
+    led.period(4.0f);      // 4 second period
+    led.write(0.50f);      // 50% duty cycle, relative to period
+    //led = 0.5f;          // shorthand for led.write()
+    //led.pulsewidth(2);   // alternative to led.write, set duty cycle time in seconds
+    while(1);
 }
\ No newline at end of file