Brightness of four leds is changed by PWM.
Dependencies: mbed
Diff: pwm-main.cpp
- Revision:
- 1:151d44cd460b
- Parent:
- 0:95e37c204360
--- 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); } } -