My Example PWM program with method 2

Dependencies:   mbed

main.cpp

Committer:
neutron_striker
Date:
2015-02-15
Revision:
0:77fda962237d

File content as of revision 0:77fda962237d:

#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. 
            */
            
    }
}