Skip to content

Latest commit

 

History

History

01

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Simple Blink example

This example shows the minimal code to blink the built-in LED in Arduino Uno board.

Execute

Arduino IDE

  1. Install Arduino IDE.
  2. Download the AsyncBlinker.zip library and import in your Arduino IDE.
  3. Restart the Arduino IDE and open the example in menu (File > Examples).
  4. Compile and load the example to your board.

Platformio

  1. Install Platformio Core.
  2. Execute pio run -t upload to load the example to your board.

Code explanation

This example shows how to:

  1. Write a callback function that switches a LED:

     void blink_my_led(bool enable) {
         digitalWrite(PIN_LED, enable ? HIGH : LOW);
     }
    
  2. Declare the AsyncBlinker instance to execute the callback function:

     AsyncBlinker blinker(blink_my_led);
    
  3. Indicate to the AsyncBlinker to start the blinking:

     blinker.start();
    
  4. Execute the non-blocking code in the main loop to blink the led:

     blinker.tickUpdate(elapsed_millis);
    

Code notes

Another yet blink example?

Yes! But this blink is non-blocking (no delays). You can do more things in the main loop and the blinking continues.

Of course, you mustn't use another code blocking the execution (delaying) or the blinker won't update the state...

Elapsed time in the Arduino framework

The code also shows how to get the system time and calculate the elapsed milliseconds in the main loop of the Arduino framework:

    static unsigned long last_millis = 0;
    unsigned long now_millis = millis();
    unsigned long elapsed_millis = now_millis - last_millis;
    last_millis = now_millis;

Default blinking time intervals

This example is using the default blinking behaviour:

  1. 500 ms enable
  2. 500 ms disable
  3. start again

Go to next example and learn about blinking intervals.