Jose Rios
/
Nucleo_BlinkWithoutWait
An active blinking led program (without the delay causes from the use of wait() function)
main.cpp@0:33741587427a, 2014-09-08 (annotated)
- Committer:
- jose_23991
- Date:
- Mon Sep 08 20:10:18 2014 +0000
- Revision:
- 0:33741587427a
Version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jose_23991 | 0:33741587427a | 1 | #include "mbed.h" |
jose_23991 | 0:33741587427a | 2 | |
jose_23991 | 0:33741587427a | 3 | const long interval = 1000; // Time between blink (1s) |
jose_23991 | 0:33741587427a | 4 | |
jose_23991 | 0:33741587427a | 5 | int main() |
jose_23991 | 0:33741587427a | 6 | { |
jose_23991 | 0:33741587427a | 7 | Timer timer; // Create the Timer object |
jose_23991 | 0:33741587427a | 8 | DigitalOut led(LED1, 0); // Create the LED object and setup OFF |
jose_23991 | 0:33741587427a | 9 | unsigned long currentMillis, previousMillis; // Variables for time reading |
jose_23991 | 0:33741587427a | 10 | |
jose_23991 | 0:33741587427a | 11 | timer.start(); // Start the Timer |
jose_23991 | 0:33741587427a | 12 | previousMillis = timer.read_ms(); // Read the actual time |
jose_23991 | 0:33741587427a | 13 | while(1) |
jose_23991 | 0:33741587427a | 14 | { |
jose_23991 | 0:33741587427a | 15 | currentMillis = timer.read_ms(); // Read the actual time |
jose_23991 | 0:33741587427a | 16 | if(currentMillis - previousMillis > interval) // Compare if the time between blink has success (interval == 1s) |
jose_23991 | 0:33741587427a | 17 | { |
jose_23991 | 0:33741587427a | 18 | led = !led; // Toggle the LED state |
jose_23991 | 0:33741587427a | 19 | previousMillis = currentMillis; // Save the last time you toggle the LED |
jose_23991 | 0:33741587427a | 20 | } |
jose_23991 | 0:33741587427a | 21 | } |
jose_23991 | 0:33741587427a | 22 | } |