Brightness of four leds is changed by PWM.

Dependencies:   mbed

Committer:
titanium
Date:
Sun Apr 01 04:13:00 2018 +0000
Revision:
0:95e37c204360
pwm controlled blinky vers. 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
titanium 0:95e37c204360 1 #include "mbed.h"
titanium 0:95e37c204360 2
titanium 0:95e37c204360 3 PwmOut pwmled1(LED1), pwmled2(LED2);
titanium 0:95e37c204360 4 PwmOut pwmled3(p22), pwmled4(p23);
titanium 0:95e37c204360 5 Serial pc(USBTX, USBRX);
titanium 0:95e37c204360 6
titanium 0:95e37c204360 7 void changeled(PwmOut *led)
titanium 0:95e37c204360 8 { float val;
titanium 0:95e37c204360 9 val= led->read() * 1.03 +0.01;
titanium 0:95e37c204360 10 if (val>0.99) val=0.0;
titanium 0:95e37c204360 11 led->write(val);}
titanium 0:95e37c204360 12
titanium 0:95e37c204360 13 void changeled_rev(PwmOut *led)
titanium 0:95e37c204360 14 { float val;
titanium 0:95e37c204360 15 val= led->read() * 0.97 - 0.01;
titanium 0:95e37c204360 16 if (val<0.01) val=0.99;
titanium 0:95e37c204360 17 led->write(val);}
titanium 0:95e37c204360 18
titanium 0:95e37c204360 19 int main() {
titanium 0:95e37c204360 20 while(1) {
titanium 0:95e37c204360 21 changeled(&pwmled1);
titanium 0:95e37c204360 22 changeled_rev(&pwmled2);
titanium 0:95e37c204360 23 changeled(&pwmled3);
titanium 0:95e37c204360 24 changeled_rev(&pwmled4);
titanium 0:95e37c204360 25 wait(0.05); } }
titanium 0:95e37c204360 26