Here at pi-top we love using Scratch with our physical computing projects so we decided it would be a good idea to share with you one of our favourite projects in honour of Scratch Day on the 11th of May 2019: Quick Reaction Game.
When we’re out and about running workshops, we often show students how to create a Quick Reaction Game - a simple game with two buttons and an LED where two players have to hit their button the fastest when the LED goes out. Sounds fun, right? Just grab your pi-top, a few components and let's get hands-on!
Building the Circuit
The first thing you’ll need to do to is to build your circuit. You’re going to need one LED and resistor, two buttons and, depending on whether you’re using a pi-topPROTO or pi-topPROTO+ board 5 m/f and a bread board or just 5 m/m jumper cables.
We connected the LED to pin 15 and the two buttons to pins 3 and 4 and then had to use the special GPIO extension blocks in order to set up the pins as either inputs or outputs.
Writing the Code
Our code was pretty simple. We used broadcast blocks to ensure that the buttons weren’t ‘live’ until the LED turned off. The hardest part was figuring out how to make sure that the code looked for just the first button push and that one was declared the winner. We were able to use a ‘repeat until’ block combined with ‘not gpio 3 high’ to detect when the button was pushed. We finished up with ‘stop other scripts in sprite’ to ensure the winning button push ended the game.
Finally, we added a few fun touches like some ‘say’ messages and a change of background depending on who the winner is.
Have some fun
[wpvideo NJ9tdRhb ]
As you can see in the video, we had great fun in the pi-top office seeing who had the fastest reactions, especially because with Scratch, everything is much more visual!
We hope you have a good time putting together your own game and if you recreate it, please tag @Getpitop so we can see your cool creation.
Have a great Scratch Day!