Wire up a circuit similar to the one below. Take what you have learned in "Toggle On and Off" and "Counting Presses" to create a program that will cause all of the lights to turn on when you press the button. The lights should stay on even after you release the button. Only when you press the button again should they turn off. Hints: - You will need to create a variable to keep track of whether the LEDs are on or off.
- If you ask something like if (ledPin13 == HIGH) you are really asking if 13 equals 1. I'm pretty sure it does not.
- You can't do digitalRead(ledPin13) because ledPin13 is an output, not an input.
Additional Tasks: - Make it flash: Pressing the button once causes all the lights to flash, pressing again stops the flashing and turns them all off.
- Make a turn signal: Pressing the button lights each light in sequence over and over again until you press the button again.
|