Collect the following parts.
In addition to these parts, you will need an Arduino UNO or Mehackit Board, a USB cable, a breadboard and a bunch of jumper wires.
|3 x LED|
Pick any kind of LED you like!
|3 x Resistor 330Ω (or 220Ω)|
This resistor is 330 ohms
|3 x pushbutton|
Make a circuit according to the diagram below.
- Three LEDs to pins 5, 6, and 7, and through 330Ω (or 220 Ω ) resistors to ground
- Three buttons to pins 2, 3, and 4, and to ground.
Click the link to the reaction game code below
- Select the whole code and copy it to the clipboard
- Open Arduino IDE and paste the code
- Upload the code to your board and test the game!
If it doesn't work: check the circuit connections! Make sure you copied and pasted the whole code!
- Can you find the part in the code where one pin is set up as a piezo
pin? Connect a piezo speaker to that pin and play the game.
Find and modify the commands that produce the sound in the code!
- Play the game for a while and then think about how you could improve it. Write down your improvement ideas. You can think about the interaction, appearance, game mechanics, additional features, and so on.
- Check out the instructions for Exercise 1: Make Your Own Switch. Could you
make a completely different user interface for the game? A game
that's played by sitting on self-made switches?
Hold on to those ideas! When you learn more about Arduino, you may code and build them, bringing them to life!
Arduino Game Example
This project is built around the same kind of board you have been using! Instead of buttons there’s a joystick and a motor turns the doll head until it reaches the correct spot - but the idea pretty similar!
"Hey, this is not real programming, we're just using ready-made code!"
In this exercise the students don't write the whole code themselves. The comment above "copying code is not real programming" came from a real-life secondary school student, and it makes sense if you're just starting with programming.
Using ready-made code in this exercise serves many purposes.
- You learn to appreciate what you already know: you understand big chunks of the code already. You also learn not to panic when you don't understand everything (which is common for pretty much all programmers!)
- You learn to appreciate other people's code: willingness to share cool things helps the whole community of programmers and makers. We made this game at Mehackit and shared the code to be used as a basis for further creation. The code is shared under the Creative Commons Licence CC-BY-2.0, which means you can use this code as the basis for your own work as long as you give credit to the original creator.
- Using ready-made code is a real world practice: programmers seldom start with an empty IDE window, from line 0. They rely a lot on libraries, code examples and code already produced in other projects they or their colleagues have been working on.
- You get an idea of what you can make with Arduino! You don't learn how to write this whole code by yourself, but the experience of having made a reaction game remains. You can return to this project later on, or use it and develop the idea in a new context.
Extra features & ideas
The students may not have the skills to code all these features right away, but feel free to return to the exercise after finishing Electronics & Programming basics!
- Keep track of the score
You'll need a variable to store every correct button press. In the program, there's the variable
questionIndexwhich stores this information! You could print this to the serial monitor (see next chapter for instructions), or connect an LCD display and have it show the score
- High score
You need a variable for the high score. Also, you need to store the final score of each finished game and compare it with the high score. If the latest score is higher than the high score, it is stored into the high score variable.
You can print the high score eg. into the serial monitor or an LCD display.
Identify the piezo pin number from the code, connect the piezo and check what sounds the game makes. Make better sounds with the
tonecommand. You can also add a melody into the
- Change the timing of events
Identify the variables that deal with timing the game events. Modify them and change the difficulty of the game.
- Different game controls
What should the game be played with? A mallet, feet, magnets? Replace the pushbuttons with self-made switches or some other type of switches for a completely different game experience.
Design and build a structure to hide the electronics and to present the LEDs and game controls in a nice way!
- You name it!
There's no way to list all the possible modifications - go ahead and imagine new hacks!