![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
NUCLEO-F042K6 Simple demo blinking LED using Timer
Dependencies: mbed
Revision 0:da8805cd0051, committed 2018-02-17
- Comitter:
- vodsejak
- Date:
- Sat Feb 17 16:44:23 2018 +0000
- Commit message:
- v1.0;
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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Feb 17 16:44:23 2018 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +/******************************************************************************* + + EXAMPLE DESCRIPTION + + Program toggles onboard LED with 1 Hz frequency. It uses timer, which is + periodically read (1 ms) and if its value is higher than that of variable the + LED is toggled. After that variable is incremented so timer has not to be + reset. + +*******************************************************************************/ + +Timer tim; // Timer definition +DigitalOut LED(LED1); // definition of digital out pin + +// returns Timer value +int getTimerVal(Timer *tim) { + int time = tim->read_ms(); + // reset when overflow + if (time<0){ + tim->reset(); + time = tim->read_ms(); + } + + return time; +} + + +int main() +{ + LED = 0; // turn LED on + int timeCompare = 500; // time for comparison + int time; // timer time + tim.start(); // start Timer + while (true) { + time = getTimerVal(&tim); // get timer time + if(time>timeCompare){ + LED=!LED; // toggle LED + timeCompare=time+500; // increment time for comparison + } + wait_ms(1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Feb 17 16:44:23 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/7130f322cb7e \ No newline at end of file