![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
My Example PWM program with method 2
Revision 0:77fda962237d, committed 2015-02-15
- Comitter:
- neutron_striker
- Date:
- Sun Feb 15 20:01:59 2015 +0000
- Commit message:
- My Example PWM program with method 2
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 Sun Feb 15 20:01:59 2015 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" + +PwmOut mypwm(LED1); + + + +int main() { + + + + printf("pwm set to %.2f %%\n", mypwm.read() * 100); + + float pwm=0.0; + + while(1) { + + pwm = pwm + 0.05; // instead of this pattern we can also write like check below + mypwm.write(pwm); + if(pwm >= 1.0) + pwm = 0.0; + wait(0.03); + + /* + mypwm = mypwm + 0.01; + if(mypwm >= 1.0) + mypwm = 0.0; + wait(0.05); + //and here we will not need any "float pwm=0.0;" type vars + //another thing is that even if we don't set the pwm.period default period will be used which will be + //same across the whole program for any number of pwms used on that chip. + */ + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Feb 15 20:01:59 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa \ No newline at end of file