Control the intensity of a single LED ( in series with 50 ohms) on PA_10

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cdupaty
Date:
Thu Mar 19 10:05:36 2015 +0000
Commit message:
A PWM LED light control

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 19 10:05:36 2015 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+
+#define per 0.001
+#define delta 0.0001
+
+PwmOut ledpwm(PA_10);
+
+
+int main() {
+float w=0; 
+int sens=0;   
+    ledpwm.period(per);
+    ledpwm.pulsewidth(delta);
+    while(1) {
+           if (sens) {
+                    w+=delta;
+                    if (w>=per) sens=0;
+                }
+           else {
+                    w-=delta;
+                    if (w<=0) sens=1;
+                }
+           wait(0.04);
+           ledpwm.pulsewidth(w); 
+           printf("pwm est de %.2f %%\n\r", ledpwm.read() * 100);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 19 10:05:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0
\ No newline at end of file