Two LEDs blink at different frequencies controlled by two timers. Two additional LEDs connected to PWM change brightness gradually also at different rates.

Dependencies:   mbed

Committer:
titanium
Date:
Fri Mar 30 13:43:01 2018 +0000
Revision:
1:75e11b7fe6d7
Parent:
0:3eb6cb11b409
extra lines are deleted.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
titanium 0:3eb6cb11b409 1 #include "mbed.h"
titanium 0:3eb6cb11b409 2
titanium 0:3eb6cb11b409 3 Ticker timer1, timer2, timer3, timer4;
titanium 0:3eb6cb11b409 4 DigitalOut digled1(LED1), digled2(LED2);
titanium 0:3eb6cb11b409 5 PwmOut pwmled3(LED3), pwmled4(LED4);
titanium 0:3eb6cb11b409 6 DigitalOut digout7(p7);
titanium 0:3eb6cb11b409 7
titanium 0:3eb6cb11b409 8 void flipled1() { digled1 = !digled1;}
titanium 0:3eb6cb11b409 9 void flipled2 () { digled2 = !digled2; }
titanium 0:3eb6cb11b409 10 void changeled3()
titanium 0:3eb6cb11b409 11 { static float pwmval=0.0;
titanium 0:3eb6cb11b409 12 static int seq=0;
titanium 0:3eb6cb11b409 13 seq=(seq+1) % 100; // 1-100
titanium 0:3eb6cb11b409 14 pwmval= float(seq*seq) / 10000.0;
titanium 0:3eb6cb11b409 15 pwmled3.write(pwmval); }
titanium 0:3eb6cb11b409 16 void changeled4()
titanium 0:3eb6cb11b409 17 { static float pwmval=0.0;
titanium 0:3eb6cb11b409 18 static int seq=0;
titanium 0:3eb6cb11b409 19 seq=(seq+1) % 100; // 1-100
titanium 0:3eb6cb11b409 20 pwmval= float(seq*seq) / 10000.0;
titanium 0:3eb6cb11b409 21 pwmled4.write(pwmval); }
titanium 0:3eb6cb11b409 22
titanium 0:3eb6cb11b409 23 int main() {
titanium 0:3eb6cb11b409 24 timer1.attach(&flipled1, 0.8);
titanium 0:3eb6cb11b409 25 timer2.attach(&flipled2, 0.35);
titanium 0:3eb6cb11b409 26 timer3.attach(&changeled3, 0.005);
titanium 0:3eb6cb11b409 27 timer4.attach(&changeled4, 0.003);
titanium 0:3eb6cb11b409 28 while(1) { digout7= ! digout7; } }
titanium 0:3eb6cb11b409 29