Edoardo Vignali / Mbed 2 deprecated fading_pwm_led2

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Calamaro
Date:
Fri Feb 20 17:14:01 2015 +0000
Parent:
2:073d39b53874
Commit message:
introducted fading on LED2;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Feb 20 17:02:50 2015 +0000
+++ b/main.cpp	Fri Feb 20 17:14:01 2015 +0000
@@ -1,15 +1,21 @@
 #include "mbed.h"
 
 PwmOut mypwm(PA_5);
-int pulse_per = 10;
-
-int main() {
+int pulse_per = 100;
 
-for(int i = 0, i < pulse_per, i++){
-    mypwm.period_ms(pulse_per);
-    mypwm.pulsewidth_ms(i);
-  
-    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
+int main()
+{
+    while(1) {
+        for(int i = 0; i < pulse_per; i++) {
+            mypwm.period_us(pulse_per);
+            mypwm.pulsewidth_us(i);
+            wait(0.01);
+        }
+        for(int i = pulse_per; i > 0; i--) {
+            mypwm.period_us(pulse_per);
+            mypwm.pulsewidth_us(i);
+            wait(0.01);
+        }
+
     }
-
 }