Change LED brightness brightness from 0 to 100%

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
virajjayaweera
Date:
Fri Jul 12 13:40:29 2013 +0000
Commit message:
PWM test with the onboard LED

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 adc859eb22d0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 12 13:40:29 2013 +0000
@@ -0,0 +1,24 @@
+//Change the brightness of onboard LED using PWM
+// Tested with FRDM-KL25Z board
+#include "mbed.h"
+
+PwmOut led(LED1);
+
+
+int main()
+{
+   float duty_cycle = 1; //PWM output is inverted for LED. Therefore duty_cycle = 1 means LED off   
+    
+   led.period_ms(1); // PWM freequency = 1/period = 1 kHz
+
+    while(1)
+    {
+        led = duty_cycle;  // also "led.write(duty_cycle)" will do the same thing
+        duty_cycle = duty_cycle - 0.01;
+        wait(0.05); // delay for visually see the effect 
+        
+        if(duty_cycle <= 0)
+            duty_cycle = 1;
+        
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r adc859eb22d0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jul 12 13:40:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file