Dushyant Singh
/
PWM_LED_RGB
pwm
Fork of PWM_LED_RGB by
main.cpp
- Committer:
- NghiaJenius
- Date:
- 2014-08-07
- Revision:
- 0:c7e6fec3dbe9
- Child:
- 1:4b22168798e5
File content as of revision 0:c7e6fec3dbe9:
#include "mbed.h" //Basic PWM Led Control In Digital Port //DigitalOut RLED(PTB22); //DigitalOut GLED(PTE26); DigitalOut BLED(PTB21); float period=0.01;//Config. Period of PWM float t_on; float t_off; double duty=0; //Duty Cycle (%) unsigned int count=0; int main() { BLED=0; //Calculate on and off time t_on= period*duty; t_off= period - t_on; while (true) { if(count<=2)//Time between changes in brightness = count*period count++; else { count=0; if(duty<1) duty+=0.01;//Adjust dimming speed else { duty=0; } t_on= period*duty; t_off= period - t_on; } //LED control wait(t_on); BLED=1; wait(t_off); BLED=0; } }