Introduction: Test a Bare Arduino, With Game Software
Interactive game using a bare Arduino board, no external parts or wiring needed. Shown above, demonstrates it running on two different boards.
Push-It has two purposes.
- To quickly demonstrate/verify that your Arduino board works and that you are setup properly to download a new code sketch to it. You'll be able to see that it performs input and output (sense digital input level, output to the on board LED); store and recover a value from the non-volatile EEPROM memory. All without attaching any wires or devices.
- Provide an entertaining and challenging game interacting with an Arduino board.
This instructable assumes that you already have installed an Arduino IDE and are at least minimally familiar with it's use. If not I refer you to these links:
Push-It will work with most any Arduino board, e.g. a Nano , Uno, or DigiSpark Attiny85 board.
I have tested it with a Nano 3.1 and a DigiSpark.
In the text when I refer to pins names/numbers they will be as used on the Nano board (as opposed to the DigiSpark).
Step 1: Having the Things You'll Need
Which is simply any Arduino or comparable board.
If you don't already have one I recommend to get started with a DigiSpark Pro (~$12), or a Nano 3.0 from eBay for ~$3 (but you'll have a extra week or two to wait for it to come from China; and you'll need to install a CH340 USB driver). The DigiSpark ~$10 (non Pro) is very well suited for this single bit 'video' game (This stripped down unit, having only 6 I/Os, is a little trickier to upload to)
Links to the hardware used herein:
Step 2: Fetch and Download the Code
Copy the code below into an arduino sketch file (e.g. …/Push_It/Push_It.ino)
I have tried to comment it fairly well. I hope you find the code easily understandable. The logic to determine when to increase, decrease and when not to is somewhat complicated, but that portion is also specialized code and is not of general usefulness.
For more details on setting up a new 'sketch' (code project) to be used with the Arduino IDE see:
Download the 'Push_It' sketch into our microcontoller per the Arduino IDE instructions for your board.
Step 3: Playing
The goal of the game is to get the LED (on-board) to blink as many time as possible in a set of flashes which then repeats
Playing the game:
Push-It starts off with a single flash, which will then repeat. If you touch your finger near the input pin while the LED is on, the next cycle will flash the LED twice.
Each time you push the pseudo button during the first flash of a set of flashes another flash will be added to that set. It does not generally matter when you lift/remove your finger.
But if you 'push' before or after the first flash the count of flashes in a set will be reduced.
If you do nothing more, the number of flashes in a set is maintained. Further when the count goes unchanged for a full cycle the count number is stored into EEPROM memory.
Every time you manage to increase the flash count the timing speeds up a little, making it harder and harder to get up to high flash counts. When you do make a slip up and the number of flashes gets reduced there will be a longer pause before the starting flash of the next cycle. This provides an added challenge, as it can increase the likelihood of you jumping the gun. So stay alert.
Once you have gotten your unit up to a high flash count you can take it (or mail it, which the DigiSpark is good for) to a friend, where upon plugging it in they will see how high a flash count you have gotten yours up to. I have found it quit challenging to get it up to more than 8. With an actual button attached I have managed to get it up to over a dozen. To revert back to a lower count you can repeatedly push-it anytime before or after the first flash. Also if you jumper the input pin to ground during a power up the count will get reset to 1.
Note that the original DigiSpark board has a delay of 10 seconds after power on before which it will begin to perform the 'Push-It' code and play the game. It uses this time to try to talk through the USB pins in order to receive a possible new download code update.
If the Arduino board you are using has a USB TX LED on it, this LED will have a quick tiny flash when you have effectively 'pushed the button'. There will be more significant flashing of this LED when ever the count value in the EEPROM is updated with a new value. This feedback can aid you greatly in knowing when or insuring that you have effectively triggered a 'pushed button' event. You may need to ensure that you are not touching circuit ground ( like the metal around a micro-USB connector) so that your figure does indeed induce noise on to the open input pin. There will be added and somewhat unpredictable challenges due to the fact that the input pin is floating (not pulled up or down by a conductive/resistive load) and the variable signal noise coming through your finger.
A 250Hz square wave is outputted to a pin next to the input pin which greatly improves the certainty of an injected input signal when your finger covers both pins.
I have found the DigiSpark board's respond to be fairly consistently predictable to a little squeeze of the fingers to the corner of the board where D3-D5 are.
When I play 'Push-It' I like to do so with the board connected to a USB 5v mobile battery pack (see photos). These can generally be found inexpensively in bins next to those of USB AC and 12v auto adapters; in most any department stores electronics department.
Step 4: Optional Experiments With External Components
Please note: If you do attach a real button there is one line of code which needs to be commented out, as stated in the code.
With a speaker, one side to ground, if you touch the other lead to D4 you'll hear the sound of a 250 Hz square wave. At D3 there is a 500Hz square wave. If you connect the speaker between D3 and D4 you will hear a composite of the two signals.
Hooking up an LED instead of a speaker as above is very interesting. There is no need to be concerned about voltage, current levels, resisters, or even polarity for that matter (worse case it doesn't light, then just turn it around). Try, first of all, with the negative (cathode) lead connected to ground and the other to either D3 or D4. The LED will be 'half' lit, due to the square waves. Further no resister is required as the output of the MicroControllerUnits are current limited. I made current measurements resulting in 15ma and 20ma for the Attiny85 and the Atmega328 MCUs respectively. These levels are about half the current limited value for these parts due to the 50% duty cycle nature of the driving square wave signals. The meter's readings are actually an average of the current through the tested circuit.
Interestingly, if you bridge between D3 & D4 with the LED (see image above and to the left) it will light either way, and at about ½ the brightness as it did with one side connected to ground.
I invite you to ponder why.