Alternating blink

14,366
Author: Yisong Xu, Si Xu

The left onboard LED light begins to flash blue for 1 second and then turns off, at this time, the right one begins to flash blue for 1 second and then turns off. This process repeats without stop.

Hardware requirements:

mBot/mCore Control Panel

Implementation:

Upload the program to Arduino

Example program download:

Alternating blink.sb2

download

Effect demo
scratch

 

Example programs
scratch

 

Script description

scratch Using the “All/Left/Right” options to choose the LED light.
Figures represent the brightness; the larger the figure is, the more brightness it represents (range 0~255).
scratch When the color parameters are 0, the LED light is off. Use this block to keep LED light off.
scratch Different time can be set to control the blink frequency of the LED light.
scratch

Repeat the contained script to control the blink frequency.

 

Knowledge points

Point 1 Why use the block scratch  to reset the LED?
The two onboard LEDs are individually controlled, and in the current mode it will stay constant (for example, if you make the left LED light up, it will remain constantly lit). If you carry out the script to light up the right-side LED, it will not change the state of the left-side LED, but you will see that both LEDs will stay continuously lit. Therefore, in order to achieve the alternating flashing effect for the LEDs on both sides, you should first add the script to turn off the left side LED before the right-side LED is turned on. Similarly, you should also turn off the right-side LED before the left-side LED is turned on. In the example script, use the block scratch  to turn off all LEDs on board, and you can compare it to the following scripts and their effects.

Script Effects (please upload the program to Arduino)
 scratch

(Delete the block scratch  2.0 from the example script)

The LEDs on each side continuously light, without a noticeable alternating-flashing effect (the lit-up LEDs will not be off).

 scratch 3.0

(Replace the block scratch 2.0 from the example script)

The effect is identical to that in the example script.

 

Point 2 If you switch the positions of the block for lighting and turning off the lights, what will happen?
Now, the block are switched as shown in the picture below (the light turns on and then turns off, then waits for 1 second). Due to the fact that the light-up program does not have continuous time, you can only observe the brief flash, and the onboard LED remains largely turned off. This process is unable to achieve the alternating color flash effect.
scratch 3.0

 

Extended tasks
Change the example script to keep the color of the onboard LED light blinking between red and blue. (you need to upload the program to the Arduino)

 

 

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

—— More examples