Oliver Ainhirn
/
12022018
Timer und Ticker
Revision 0:1316a6f25ffc, committed 2019-02-04
- Comitter:
- corsa1600
- Date:
- Mon Feb 04 16:58:24 2019 +0000
- Commit message:
- Timer und Ticker
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 1316a6f25ffc main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Feb 04 16:58:24 2019 +0000 @@ -0,0 +1,55 @@ +// switch blue LEDs LED1 .. LED4 with external interrupt functionality +/* +3 classes +Timeout - Call a function after a specified delay +Ticker - Repeatedly call a function +Timer - Create, start, stop and read a timer +*/ + +#include "mbed.h" + +Timeout toFlipper; +DigitalOut doLed1(LED1); +DigitalOut doLed2(LED2); +Ticker tickBlinker; +DigitalOut doLed3(LED3); +DigitalOut doLed4(LED4); +Timer tMyTimer; +Serial pc(USBTX, USBRX); // tx, rx +int count =0; +int min=0; + +// functions +void flip() { + doLed1 = !doLed1; +} + +void blink() { + doLed3 = !doLed3; + count ++; +} + +int main() { + doLed2 = 1; + toFlipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds + tickBlinker.attach(&blink, 1.0); // setup blinker to call blink avery 500 msec + + // spin in a main loop. flipper will interrupt it to call flip + while(1) { + + if (count ==60) + { + min++; + count=0; + } + tMyTimer.reset(); + tMyTimer.start(); + //pc.printf("Hello Timer-World! "); + doLed4 = !doLed4; + wait(1.0); + tMyTimer.stop(); + pc.printf("Uhr lauft seit %iMinuten & %i Sekunden\r",min,count); + //The time taken was %f seconds\r", tMyTimer.read()); + + } +}
diff -r 000000000000 -r 1316a6f25ffc mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Feb 04 16:58:24 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e \ No newline at end of file