Make Multiple LEDs Blink (breadboard) Once we have one LED wired to the Arduino via the breadboard, it's easy to add another one. The picture below shows how we've added a yellow LED, wired in the same way as the red LED, except that it's connected to pin 4 instead of pin 3. We also introduce a very important programming concept in this activity: that of loops. (Though you may have already encountered the idea in some of the other Arduino activities.) In programming we often have situations where we need to do the same sequence of commands multiple times in a row, and a "loop" makes it easier to do this. There are several types of loops, but the version we will use in this activity is called a "repeat loop," because it tells the computer how many times to repeat a certain sequence of commands. In RoboBlocky you will find the repeat loop block in the "Loops" section (click the "Loops" button just below the "Logic" button): The code blocks to be repeated are placed inside the repeat loop block. The number inside the blue box specifies the number of times the code blocks inside the loop are repeated. We have shown how it works in the pre-placed code blocks in the Workspace. The idea is that we want to alternate turning on and off the two LEDs, and do it for four times total. The code blocks inside the repeat loop turn off the red LED (pin 3) and turn on the yellow LED (pin 4), delay one second and then turn on the red LED and turn off the yellow LED, and delay another second. The repeat loop repeats this sequence 4 times.
|
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
|
|
|
Modify the pre-placed code blocks so that both LEDs are on at the same time, and off at the same time (so they blink together), and so that they do this for 7 times total. |
|
|
|||||||||||
|
|||||||||||