![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
millis_demo
Fork of mbed_blinky by
Diff: main.cpp
- Revision:
- 7:4ff2cd962710
- Parent:
- 4:81cea7a352b0
--- a/main.cpp Fri May 09 19:58:03 2014 +0300 +++ b/main.cpp Fri Oct 31 08:07:49 2014 +0000 @@ -1,12 +1,28 @@ -#include "mbed.h" +/* + * Copyright: DFRobot + * license: GPL + * Author: lisper (lisper.li@dfrobot.com) + * Date: 2014-10-30 + * Description: example program for millis library + */ -DigitalOut myled(LED1); +#include "mbed.h" +#include "millis.h" + -int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); +DigitalOut led1(LED1); + +int main() +{ + startMillis (); //must call this function if you want use millis (); + + led1 = 0; + uint32_t lastTime = 0; + + while (1) { + if (millis() - lastTime > 1000) { + lastTime = millis (); + led1 = !led1; + } } }