four leds are enlightened and dimmed by tickers.

Dependencies:   mbed

Committer:
titanium
Date:
Sun Apr 01 04:18:25 2018 +0000
Revision:
2:768c88a138c2
not squared.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
titanium 2:768c88a138c2 1 #include "mbed.h"
titanium 2:768c88a138c2 2
titanium 2:768c88a138c2 3 Ticker timer1, timer2, timer3, timer4, timer5;
titanium 2:768c88a138c2 4 DigitalOut digled1(LED1), digled2(LED2);
titanium 2:768c88a138c2 5 PwmOut pwmled3(LED3), pwmled4(LED4);
titanium 2:768c88a138c2 6 DigitalOut digout7(p7);
titanium 2:768c88a138c2 7 Serial pc(USBTX, USBRX);
titanium 2:768c88a138c2 8
titanium 2:768c88a138c2 9 void flipled1() { digled1 = !digled1;}
titanium 2:768c88a138c2 10 void flipled2 () { digled2 = !digled2; }
titanium 2:768c88a138c2 11 void changeled3()
titanium 2:768c88a138c2 12 { static int seq=0;
titanium 2:768c88a138c2 13 seq=(seq+1) % 100; // 1-100
titanium 2:768c88a138c2 14 pwmled3.write(seq/200.0); }
titanium 2:768c88a138c2 15 void changeled4()
titanium 2:768c88a138c2 16 { static int seq=0;
titanium 2:768c88a138c2 17 seq=(seq+1) % 100; // 1-100
titanium 2:768c88a138c2 18 pwmled4.write(seq/200.0); }
titanium 2:768c88a138c2 19 void report_led()
titanium 2:768c88a138c2 20 { static int count=0;
titanium 2:768c88a138c2 21 pc.printf(" count:%d %d %d %f %f\r\n",
titanium 2:768c88a138c2 22 ++count, digled1.read(), digled2.read(), pwmled3.read(), pwmled4.read()); }
titanium 2:768c88a138c2 23
titanium 2:768c88a138c2 24 int main() {
titanium 2:768c88a138c2 25 pc.printf("Timer driven multi led blinker.\n\r");
titanium 2:768c88a138c2 26 timer1.attach(&flipled1, 0.8);
titanium 2:768c88a138c2 27 timer2.attach(&flipled2, 0.35);
titanium 2:768c88a138c2 28 timer3.attach(&changeled3, 0.007);
titanium 2:768c88a138c2 29 timer4.attach(&changeled4, 0.013);
titanium 2:768c88a138c2 30 timer5.attach(&report_led, 1.0);
titanium 2:768c88a138c2 31 while(1) { digout7= ! digout7; } } //See how fast GPIO can be toggled.
titanium 2:768c88a138c2 32