Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 //Basic PWM Led Control In Digital Port 00003 00004 //DigitalOut RLED(PTB22); 00005 //DigitalOut GLED(PTE26); 00006 DigitalOut BLED(PTB21); 00007 float period=0.01;//Config. Period of PWM 00008 float t_on; 00009 float t_off; 00010 double duty=0; //Duty Cycle (%) 00011 unsigned int count=0; 00012 00013 int main() 00014 { 00015 BLED=0; 00016 //Calculate on and off time 00017 t_on= period*duty; 00018 t_off= period - t_on; 00019 00020 while (true) 00021 { 00022 if(count<=2)//Time between changes in brightness = count*period 00023 count++; 00024 else 00025 { 00026 count=0; 00027 if(duty<1) 00028 duty+=0.01;//Adjust dimming speed 00029 else 00030 { 00031 duty=0; 00032 } 00033 t_on= period*duty; 00034 t_off= period - t_on; 00035 } 00036 //LED control 00037 wait(t_on); 00038 BLED=1; 00039 00040 wait(t_off); 00041 BLED=0; 00042 } 00043 00044 }
Generated on Fri Jul 29 2022 17:26:38 by
1.7.2