Brightness of four leds is changed by PWM.
Dependencies: mbed
pwm-main.cpp
- Committer:
- titanium
- Date:
- 2018-04-01
- Revision:
- 0:95e37c204360
File content as of revision 0:95e37c204360:
#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); } }