|
In previous activities for the Arduino with LED virtual simulation, we used a combination of the virtualWrite and delay code blocks to turn an LED on and off. This works well for one or two blinks, but if we want to do multiple blinking the number of blocks required becomes cumbersome. For a real Arduino with RGB LED module, the digitalWriteHighLow block simplifies the process of doing multiple blinks. It sends ("writes") a sequence of high and low signals to one of the Arduino digital pins:
The virtual version of this code block is the virtualWriteHighLow block:
For blinking an LED, the input values we specify are the pin number that the LED is connected to (e.g., pin 13 for the red LED, pin 12 for the green LED, and pin 11 for the blue LED, if we are using the LED module connected to the Arduino), the length of time to be on ("high") in milliseconds (thousandths of a second), the length of time to be off ("low") in milliseconds, and the number of blinks to do. Example 1 shows how it works.
Note that the virtualPinMode and virtualWriteHighLow code blocks are defined as functions. If you scroll down in the Workspace you can see their code. It's a good exercise to study it to see how it works, but don't change it. (Or, if you want to experiment with it, save a copy of the code for your own use.) Click the More Info button at top right for more information on creating and using functions in RoboBlockly.
|
Use the virtualWriteHighLow command to blink the red LED 4 times, with the blinks being 2 seconds on and 1 second off. |
| Grid Size: S M L | Simple View: | MinView: |
| Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
| Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
| 72x72 inches | 96x96 inches | 192x192 inches | ||
| 1x1 inches | 2x2 inches | Fraction: | ||
| xy-Range: | ||||
|
|
||||
|
|
||||
| Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
| Units: | US Customary | Metric | Ruler: | |
| Labels: |
|
|
|
|
Font
px
|
|
| Tics Lines: |
|
Width
px
|
| Hash Lines: |
|
Width
px
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
|||||||||||
|
|||||||||||
