Brightness of four leds is changed by PWM.
Dependencies: mbed
Revision 1:151d44cd460b, committed 2018-05-15
- Comitter:
- titanium
- Date:
- Tue May 15 04:03:38 2018 +0000
- Parent:
- 0:95e37c204360
- Commit message:
- file name is changed to pwm_blinky.cpp
Changed in this revision
pwm-main.cpp | Show diff for this revision Revisions of this file |
pwm_blinky.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 95e37c204360 -r 151d44cd460b pwm-main.cpp --- a/pwm-main.cpp Sun Apr 01 04:13:00 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#include "mbed.h" - -PwmOut pwmled1(LED1), pwmled2(LED2); -PwmOut pwmled3(p22), pwmled4(p23); -Serial pc(USBTX, USBRX); - -void changeled(PwmOut *led) -{ float val; - val= led->read() * 1.03 +0.01; - if (val>0.99) val=0.0; - led->write(val);} - -void changeled_rev(PwmOut *led) -{ float val; - val= led->read() * 0.97 - 0.01; - if (val<0.01) val=0.99; - led->write(val);} - -int main() { - while(1) { - changeled(&pwmled1); - changeled_rev(&pwmled2); - changeled(&pwmled3); - changeled_rev(&pwmled4); - wait(0.05); } } -
diff -r 95e37c204360 -r 151d44cd460b pwm_blinky.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pwm_blinky.cpp Tue May 15 04:03:38 2018 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" + +PwmOut pwmled1(LED1), pwmled2(LED2); +PwmOut pwmled3(p22), pwmled4(p23); +// Serial pc(USBTX, USBRX); + +void changeled(PwmOut *led) +{ float val; + val= led->read() * 1.03 +0.01; + if (val>0.99) val=0.0; + led->write(val);} + +void changeled_rev(PwmOut *led) +{ float val; + val= led->read() * 0.98 - 0.01; + if (val<0.01) val=0.99; + led->write(val);} + +int main() { + while(1) { + changeled(&pwmled1); + changeled_rev(&pwmled2); + changeled(&pwmled3); + changeled_rev(&pwmled4); + wait(0.05); } } +