A program to create a blinking LED can be defined in this manner:

  1. Turn on an LED.
  2. Wait a moment
  3. Turn off the LED.
  4. Wait a moment.

The function Blink defined in this manner is illustrated in Figure 19 below. In this mBot program, a Forever loop is used to cause LED 15 to blink forever (or until another command is executed).

Defining a Function that Blinks

If the command Turn_On LED is replaced with Blink_LED, a traveling LED can be created that travels the length of the LED strip. Compare the All_On function with the Traveling LED function below. They are identical except for one line.

Using Blink to Create a Traveling LED Procedure

The second delay statement (Wait 0.1 Seconds) is not needed when the Blink function is used in the Traveling_LED procedure. It just slows down the movement of the LED as it travels down the strip. A variant of Blink named Flash omits the second Wait statement. This adjustment results in a more fluid movement of the LED as it travels across the strip.

Creating a More Fluid Movement in the Traveling LED Procedure