In a previous activity we used red, yellow, and green LEDs to create a miniature traffic light. In this lesson we will learn how to add a push button switch to operate the light. Wire the red, yellow, and green LEDs, with 220-ohm resistors, to the breadboard as shown in the diagram below (digital pins 3, 4, and 5): Remember that the longer leg of each LED (shown with a kink in the image) is connected to the pin, and the shorter leg is connected through the resistor and then to ground. For the push button switch, connect one side to the 5V column (short red wire in the diagram) and the other side through a 10K-ohm resistor (brown-black-orange) to ground. Between the resistor and the push button make a connection to pin 2 (the orange wire).
|
Create the code so that when the button is unpushed, the red LED is on. If you push the button, the code should turn off the red LED and turn on the green LED for 3 seconds, and then turn on the yellow LED for 1 second before going back to red. (Click the "More Info" button at the top right for more about the code.) |
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
|
|
|
|||||||||||
|
|||||||||||