loading

"Push-It"
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.

  1. 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.
  2. 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:

Getting Started with Arduino

Adding Digispark (with bootloader) support to existing Arduino 1.6.x IDE

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:

Nano V3.0 Atmega328P on eBay

Digispark USB Development Board

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:

Creating a New Arduino Sketch

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.

<p>I tried to get this working on a bare ATTiny85 on a breadboard. I used a hardwired switch on D5 and hooked up a LED to D0. The only changes to the code I made was to define ledOnBrd=0, comment out the code to allow a wired button, and comment out all serial output lines as my tiny core doesn't support serial.</p><p>I get a slow flashing LED on power up. When I press the button (when the LED is on) the LED goes out. On button release it just goes back to the normal slow flash. So I can't seem to get it to do anything beyond that.</p><p>Any ideas? I know you didn't write this for a bare chip so I'm just wondering if you can think of anything off the top of your head? Would the fact that my ATTiny85 is running at 8Mhz instead of 16Mhz matter?</p><p>Thanks!</p>
<p>I just rechecked operation with an actual button. I had not done that for quite some time. It did work fine for me. It sounds like you did as I directed in the comments of the code, for use with a button. Note however that you don't have to hold the button pressed, simply push it &amp; let go. </p><p>But I think it should have worked for you (regardless of Mhz) ... and went to two slow flash sets. </p><p>Check the ground side of the switch; or better yet meter D5 to see that it is normally high and goes low when the button is pressed. .... Best of Luck Ron</p><p>Others may want to use a bare chip, so let us know what you find.</p>
Thanks for your reply Ron. I actually have Digispark too, although it's a clone and has headers soldered instead of a bare board. I flashed it with your unmodified code (using the Digispark core) and can't get that to work either. I see exactly the same behavior, a slow blinking LED that doesn't do anything else. I'm using the latest Arduino IDE release and the latest Digispark core. I haven't used a switch in this case (yet) and tried the fingers method.<br><br><br>I'll spend some more time trying to figure out if I'm doing something wrong.
<p>I have one of those clones with the micro USB connector on it. I like the configuration but it has failed to work in most of my projects. I just tried it with the 'Push It' code and got the same results has you, &amp; worst when I used a button it does a reset when I push it. I think these are bad clones.</p><p>I have had great success with the Nano 3.0 and Pro Minis through eBay. They are just as inexpensive. The Pro Mini is even better for low power battery (3.0 or 3.7) use, as they have no voltage regulator on the board; which causes notable drain needlessly, in that case. On my Digispark I cut the leads to the regulator. Note that with the Pro Mini <a href="http://www.ebay.com/itm/261791591581" rel="nofollow">http://www.ebay.com/itm/261791591581</a> you'll need a USB/TTL Converter <a href="http://www.ebay.com/itm/271751638102" rel="nofollow">http://www.ebay.com/itm/271751638102 </a>and associated driver to download to it.</p>
<p>Got it working! First I got serial output working so I could see what was going on (using SoftwareSerial) and it was clear that D5 was always LOW despite being initially set to HIGH. On pressing the button, serial output showed the press wasn't being seen. So I moved the button to D1 and it started working.</p><p>Now that it's working, I realized why. D5/pin 1 by default is the RST pin on an ATTiny85. When setting fuses you can change its function to being another I/O pin which is what Digispark must have done. So every button press on D5 was resetting the ATTiny. I'm going to set D5 to being an I/O pin and then it should working using my finger and/or the button.</p><p>Thanks again for being patient.</p>
<p>Thanks for getting to the root of the behavior of D5 on the ATTiny85. I take it that applies to the bare chip and those extra small (with micro USB connector) Digispark like clones. </p><p>By the way I think I once owned a ZX80; but quickly switched to a C64.</p>
<p>FYI I also got it working on an ATTiny2313V which has more pins, much lower power use but only 2KB of Flash and 128B of SRAM. Whereas the ATTiny85 has 8KB of Flash and 500B of SRAM. As you can see it just fits. All I had to do was make it button only, lose the serial output plus a few other tweaks.</p><p>Sketch uses 1,970 bytes (96%) of program storage space. Maximum is 2,048 bytes.</p><p>Global variables use 38 bytes (29%) of dynamic memory, leaving 90 bytes for local variables. Maximum is 128 bytes.</p>
<p>That's Great. I enjoy making something rewarding with so little resources.</p><p>BTW, what is the maximum number of flashes you have managed to get up to ?</p><p>I think my max was 11 or 12.</p>
<p>12 is my highest I think. If I used a better button it would probably make it a bit easier.</p>
<p>From the factory the ATTiny family comes with pin 1 configured as a RST pin. Looking at my Digispark clone, they've labelled pin1 as an I/O pin, but it seems to behave like a RST pin just like a factory ATTiny. So it's entirely possible they forgot to reconfigure the fuses to make it an I/O pin which explains why it also acted the same way as my breadboard ATTiny.</p><p>I never had a ZX80, I started with a ZX81, but that username was taken. :)</p>
<p>Found my Nano and it works perfectly. So now to figure out the breadboard ATTiny85. I'll report back if I do.</p>
<p>My clone looks identical to the Digispark one. It has the same printed circuit board USB connector. But I'm totally prepared to accept that the problem could be with it being a bad clone. </p><p>I have an identical USB/TTL converter to the one you linked! I'm really starting to like the CH340 chip after the nightmares I had with a fake FTDI thing I bought on eBay.</p><p>I do have a Nano somewhere and will try that when I find it. Thanks again!</p>
<p>Just received a Digispark. When trying to compile the program I have the following error on Arduino IDE 1.6.5:</p><p>Push_It.ino:21:20: fatal error: EEPROM.h: No such file or directory</p><p>compilation terminated.</p><p>Other basic programs are working</p><p>Any hint?</p>
<p>I had been using an Arduino 1.0 IDE which I had got from Digistump. </p><p>Using the new 1.6.5-r5 (updated per <a href="http://digistump.com/wiki/digispark/tutorials/connecting" rel="nofollow"> http://digistump.com/wiki/digispark/tutorials/con...</a> ) I found it would compile when other MCU were selected, but not when a Digistump core was selected. So the compile commands used specified different 'Include' directories.<br>To resolve the issue I copied 'EEPROM.h' on my system from where Arduino 1.6.5 had it to the folder used for the Digispark core.<br>(...\arduino-1.6.5-r5\hardware\arduino\avr\libraries\EEPROM\EEPROM.h to ...\packages\digistump\hardware\avr\1.6.5\cores\tiny)</p><p>Then it compiled and worked as expected.</p>
<p>Thank you so much!. It worked perfectly!!</p>
<p>Cool!</p>
<p>Cool setup. Thanks for sharing.</p>

About This Instructable

1,587views

15favorites

License:

Bio: Professional Software, Hardware, Systems Engineer for more than 40 years.
More by RonM9:Dual Power for Your Portable Micro-Controller Project 3D printed case, Inline LED display console + reflection on 3D printing 4 Button Games using one Analog input 
Add instructable to: