NUCLEO-F042K6 Simple demo using PWM to controll LED brightness

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vodsejak
Date:
Sat Feb 17 20:28:45 2018 +0000
Parent:
3:03bf4cc245ce
Commit message:
v3.0; bugfix

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 03bf4cc245ce -r 79eee74e1bbd main.cpp
--- a/main.cpp	Wed Jan 31 21:48:21 2018 +0000
+++ b/main.cpp	Sat Feb 17 20:28:45 2018 +0000
@@ -16,18 +16,18 @@
 int main()
 {
 
-    PWM.period_ms(5); // period of PWM - f=1/T -> f=1/0.005=4200 Hz
+    PWM.period_ms(5); // period of PWM - f=1/T -> f=1/0.005=200 Hz
     PWM.pulsewidth_us(0); // duration of active pulse
                             //sets duty cycle - duty cycle = pulsewidth/period
 
     while(1) {
         for(int i=0;i<=5000;i=i+10){
             PWM.pulsewidth_us(i); // increment duty cycle
-            wait_ms(4); // wait 4 ms (whole for takes 1 s)
+            wait_ms(2); // wait 4 ms (whole for takes 1 s)
         }
         for(int i=5000;i>=0;i=i-10){
             PWM.pulsewidth_us(i); // decrement duty cycle
-            wait_ms(4); // wait 4 ms (whole for takes 1 s)
+            wait_ms(2); // wait 4 ms (whole for takes 1 s)
         }
     }
 }