Ribbit ribbit, use red and green LEDs timing to play one another
In this project, students design a timing game to play against each other. Press the button to stop the light on green. Who can get the most green in a row?
The build consists of two LED lights and a button. The lights blink back and forth and when the button is pressed, it will stop on either the red light or the green light. The objective of the game is to stop on the green light three times in a row! The step by step instructions in the tutorial guides students through the process of building the circuit and writing the code.Students will create states (turning a pin on/off), sounds and sequences. They use a ‘repeat while’ block to check the status of the button press.
Take out the inventory you see in the picture below.
Carefully study the wiring diagram. All cables must be connected exactly as seen in the image. If the LED does not work, try turning it over.
Push Button: 35, 33
First turn the green light on and the red light off. Test your code by pressing Start.
Now turn the red light off and the green light on. Test your code again.
Add a Repeat Forever block and your lights will blink red and green. Test the code.
Add two Wait blocks so the lights will blink slowly and a While loop that checks if pin 33 is on. When the button is pressed (pin 33) the game will wait.
In the Sounds library, drag the Play block into the Repeat While block.
Select the synth block and drag it inside the Play block. Change the sound by clicking on synth1.
Add the new Wait Until block to check if we hit the button at the wrong time.
Press Start and have fun!