TOW the lights is a small arcade box where you have a virtual Tug of War with another player. Who of you is quickest? In thuis guide you will learn how to make one yourself and even code it. It’s like simon says, but more fun. The ultimate battle of the reflexes.
Can’t code? Don’t worry, finished code is also provided
I recommend reading the whole document first before deciding what to buy for your own projects
4 | arcade style buttons radius 15mm |
---|---|
15 | LED’s (different colors optional) |
2 | breadboards (protoboards if you want to solder more) |
1 | Arduino Mega |
1 | on/off switch |
1 | 9-volt battery |
1 | 9-volt battery adapter |
hot glue gun | |
---|---|
case (wooden box or own design) | |
wood drill | |
Drill bit 5mm | |
Drill bit 30mm or wood file | |
Tape | |
Double sided ape | |
A lot of male to male cables for your Arduino |
3D printer |
---|
First step is deciding what kind of case you want to work with. You need to make sure there’s enough room for all your parts. Mine has a lid. This does mean we need to take the hinge into account when wiring our lights to the Arduino. You don’t need the same box as me, if you have any ideas, go wild! I started designing my own box, so it feels right to play with two players. This does leave you with lots of empty space inside, but it gives a better player experience, but before making. one myself I noticed there’s a box on amazon with roughly the same measurements. The box I ended up with is 300mm x 200mm x 150mm
Drilling the holes You need to make 4 holes in your case for the buttons (2 for each player) and 15 holes on top for the LED’s.
you need to decide where the center point of the hole will be and do that for all 4 holes. My center point is 30mm removed from the left or right edge, and 55mm from the top. Draw a cross at those points so you will know where to drill. If you are making drilling using a 30mm drill bit, make sure the center point of your bit is aligned with your cross. If you don’t have a 30mm drill bit like me, you need to draw a circle with a 30mm diameter yourself, and drill smaller wholes within that circle until you have a hole of roughly 30mm, use your wood file to smooth out any imperfections.
We need 15 holes on top of the box, 1 for each LED. My LED’s have a diameter of 5mm. Yours would most likely be the same, but double check, since you can also buy bigger LED’s (or smaller once, but it’s not recommended). You need 4 LED’s for the players, 2 on each side, and 11 LED’s for the array of lights. For the 4 player LED’s, I drilled 4 holes 35mm from the left/right edge and 40mm from the edge in length. For the 11 array lights, I drew a line in the middle of the top plane in length and drilled a hole at the absolute middle of the top. Then drilled 5 holes to the left and 5 holes to the right with 20mm of space between each hole.
Cover the holes from the inside using some tape You can really personalize your case by giving it a paint job. But don’t be forced to do so if you love the feel of RAW UNADULTERATED WOOD. As for me, I’m boring and love clean design, so I painted mine white. And I still like the texture of wood, so I only gave it 2 thin layers of white paint. For the artists among us, if you want to draw on your case, I recommend a good grounding layer with at least 2 layers on top of that with the color of your choice. This will give you an evenly colored box to draw on. At last, you want a finishing layer to protect your paint. I use Molotow graffiti cans myself with Molotow clear varnish as a finishing layer. As for art, wait until the 2 layers of color are dry and completely cured then start drawing. As for art, I recommend Posca markers, but Molotow markers would also work.
Let’s start with the 9-volt battery. If you own a 3D printer, this is the time to use it. You can design your own 9volt battery holder, or use this model to print out, it holds your 9volt battery and you can later tape it down on the bottom of your case. You’ll still need an adapter to connect the 9-volt battery to your Arduino. If you don’t have a 3Dprinter, you can buy a holder for your 9volt battery at a hobby store near you for around $1/€1. As for your Arduino, if it came with a bracket, hold it in place on your bracket with some tape, or screw it down. And use the double-sided tape to tape it on the bottom of your case. If it didn’t come with one, you can always print one yourself, buy one or just screw it to a thin piece of wood and tape that one on the bottom of your case. You also need an on/off button. I didn’t want to drill another hole into my box, so I printed an extra holder for the on off button which I glued to one of the sides within my case. You yourself could pick a place to make an extra hole, or get a switch which you could also glue / tape in your box
If all your paint is dry and varnished and made sure that you have everything read, its finally time to start assembling your box & parts (don’t forget to remove your tape). Place your 15 LED’s in the holes you drilled from the inside out. I recommend color coding your LED’s. I used White LED’s for the players, blue LED’s for the center point and the most left and right LED’s, and green, yellow and red for the 4 remaining LED’s in-between. Use your hot glue gun to glue them all in place. If you are using a Protoboard, skip this step for now Grab your 2 breadboards and place one at the center of the edge nearest to the hinge. Place the other one on the bottom of your box at the wall of the hinge. If you used another box design, make sure you can run wires from the top breadboard to the bottom breadboard. Grab your 4 arcade buttons and place them in the 4 holes from the outside.
For wiring you need to keep track of your wires through the 2 bread boards. Eventually you need this wiring scheme. You can start soldering the lights to the cables and the buttons to the cables, but not to the Arduino If you are using a protoboard, this would be the moment to start prototyping a cirquit
At last, coding. We need to program your Arduino. If you wired everything according to the scheme above, this should be the final step. Download and open the Arduino IDE and connect your Arduino. Make sure you select the right Arduino, in this case it’s the Arduino/genuino Mega/Omega board and select the right com port. Try uploading the blink sample sketch to check if you have a successful connection. If you bought a third-party Arduino and cant upload your sketch, try selecting a different bootloader / check your manual for the right settings or drivers. If you don't want to code, you can skip and download the final code.
const int button_1 = 12; //controls for player 1
const int button_2 = 11;
const int button_21 = 3; //controls for player 2
const int button_22 = 2;
pinMode(button_1,INPUT);
const int light_1 = 6; //lights for player 1
const int light_2 = 5;
const int light_21 = 9; //lights for player 1
const int light_22 = 8;
const int l1 = 32; // array of lights
const int l2 = 34;
const int l3 = 36;
const int l4 = 38;
const int l5 = 40;
const int l6 = 42;
const int l7 = 44;
const int l8 = 46;
const int l9 = 48;
const int l10 = 50;
const int l11 = 52;
// integers
int button1; //player 1 controls
int button2;
int button21;//player 2 controls
int button22;
//button state is for anti-spam
int buttonState; //checks if button is released for player 1
int buttonState2; //checks if button is released for player 2
//light randomizer
int light; //randomizer for player 1 lights
int light2; // randomizer for player 2 lights
int rope; //position of the rope
int power; // player 1 combo multiply
int power2; // player 2 combo multiply
int multiplyLimit; //combo limit
int game; //checks for start of game and game over.
// game == 0 game hasnt started
// game == 1 game has started
// game == 2 player 1 wins
// game == 3 player 2 wins
// game == 4 start animation
void setup() {
// all inputs
pinMode(button_1,INPUT);
pinMode(button_2,INPUT);
pinMode(button_21,INPUT);
pinMode(button_22,INPUT);
// all outputs
pinMode(light_1,OUTPUT);
pinMode(light_2,OUTPUT);
pinMode(light_21,OUTPUT);
pinMode(light_22,OUTPUT);
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(l3, OUTPUT);
pinMode(l4, OUTPUT);
pinMode(l5, OUTPUT);
pinMode(l6, OUTPUT);
pinMode(l7, OUTPUT);
pinMode(l8, OUTPUT);
pinMode(l9, OUTPUT);
pinMode(l10, OUTPUT);
pinMode(l11, OUTPUT);
Serial.begin(9600);
light = random(1,3); // sets light at random for player 1
light2 = random(1,3); // sets light at random for player 2
rope = 50; // sets the rope in the middle
multiplyLimit = 5; // combo limit
game = 0; // game hasnt started yet, see above.
}
void loop() {
//game hasnt started yet
if (game == 0) {
button1 = digitalRead(button_1); // reads if button is pressed for player 1 & 2
button2 = digitalRead(button_2);
button21 = digitalRead(button_21);
button22 = digitalRead(button_22);
//blinks lights
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
delay(500);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
digitalWrite (l3,HIGH);
digitalWrite (l4,HIGH);
digitalWrite (l5,HIGH);
digitalWrite (l6,HIGH);
digitalWrite (l7,HIGH);
digitalWrite (l8,HIGH);
digitalWrite (l9,HIGH);
digitalWrite (l10,HIGH);
digitalWrite (l11,HIGH);
delay(500);
// starts game if both players hold both buttons
if (button1 == 1 && button2 == 1 && button21 == 1 && button22 == 1) {
rope = 50;
game = 4; //plays intro animation
}
}
//game intro animation
else if (game == 4) {
button1 = digitalRead(button_1);
button2 = digitalRead(button_2);
button21 = digitalRead(button_21);
button22 = digitalRead(button_22);
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
delay(100);
digitalWrite (l1,HIGH);
digitalWrite (l11,HIGH);
delay(300);
digitalWrite (l2,HIGH);
digitalWrite (l10,HIGH);
delay(300);
digitalWrite (l3,HIGH);
digitalWrite (l9,HIGH);
delay(300);
digitalWrite (l4,HIGH);
digitalWrite (l8,HIGH);
delay(300);
digitalWrite (l5,HIGH);
digitalWrite (l7,HIGH);
delay(300);
digitalWrite (l6,HIGH);
digitalWrite (l6,HIGH);
game = 1;//starts game
}
// game has begun
else if (game == 1) {
button1 = digitalRead(button_1);
button2 = digitalRead(button_2);
button21 = digitalRead(button_21);
button22 = digitalRead(button_22);
//player one lights
if (light == 1) {
digitalWrite(light_1, HIGH);
digitalWrite(light_2, LOW);
}
else if (light == 2) {
digitalWrite(light_2, HIGH);
digitalWrite(light_1, LOW);
}
//player two lights
if (light2 == 1) {
digitalWrite(light_21, HIGH);
digitalWrite(light_22, LOW);
}
else if (light2 == 2) {
digitalWrite(light_22, HIGH);
digitalWrite(light_21, LOW);
// player one buttons
if (light == 1 && button1 == 1 && buttonState == 0 || light == 2 && button2 == 1 && buttonState == 0 ){
digitalWrite(light_1,LOW);
digitalWrite(light_2,LOW);
rope = rope + power;
if (power < multiplyLimit){
power = power + 1;
}
delay(5);
light = random(1,3);
buttonState = 1;
}
else if (light == 1 && button2 == 1 && buttonState == 0 || light == 2 && button1 == 1 && buttonState == 0){
digitalWrite(light_1,LOW);
digitalWrite(light_2,LOW);
rope = rope - 1;
power = 1;
delay(5);
light = random(1,3);
buttonState = 1;
}
if (button1 == 0 && button2 == 0) {
buttonState = 0;
}
//Player two buttons
if (light2 == 1 && button21 == 1 && buttonState2 == 0 || light2 == 2 && button22 == 1 && buttonState2 == 0 ){
digitalWrite(light_21,LOW);
digitalWrite(light_22,LOW);
rope = rope - power2;
if (power2 < multiplyLimit){
power2 = power2 + 1;
}
delay(5);
light2 = random(1,3);
buttonState2 = 1;
}
else if (light2 == 1 && button22 == 1 && buttonState2 == 0 || light2 == 2 && button21 == 1 && buttonState2 == 0){
digitalWrite(light_21,LOW);
digitalWrite(light_22,LOW);
rope = rope + 1;
power2 = 1;
delay(5);
light2 = random(1,3);
buttonState2 = 1;
}
if (button21 == 0 && button22 == 0) {
buttonState2 = 0;
}
// rope code
if (rope >= 0 && rope < 10){
digitalWrite (l1,HIGH);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 10 && rope < 20){
digitalWrite (l1,LOW);
digitalWrite (l2,HIGH);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 20 && rope < 30){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,HIGH);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 30 && rope < 40){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,HIGH);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 40 && rope < 50){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,HIGH);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 50 && rope < 60){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,HIGH);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 60 && rope < 70){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,HIGH);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 60 && rope < 80){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,HIGH);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 80 && rope < 90){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,HIGH);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
}
if (rope >= 90 && rope < 100){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,HIGH);
digitalWrite (l11,LOW);
}
if (rope >= 100 && rope < 110){
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,HIGH);
}
// player 1 wins
if (rope <= 0) {
game = 2;
}
// player 2 wins
if (rope >= 109){
game = 3;
}
}//end of loop 1
//game over animation
else if(game == 2) {
button1 = digitalRead(button_1);
button2 = digitalRead(button_2);
button21 = digitalRead(button_21);
button22 = digitalRead(button_22);
digitalWrite (light_1,LOW);
digitalWrite (light_2,LOW);
digitalWrite (light_21,LOW);
digitalWrite (light_22,LOW);
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
delay(100);
digitalWrite (l5,HIGH);
delay(100);
digitalWrite (l4,HIGH);
delay(100);
digitalWrite (l3,HIGH);
delay(100);
digitalWrite (l2,HIGH);
delay(100);
digitalWrite (l1,HIGH);
delay(100);
game = 0; //resets game state
}
else if (game == 3) {
button1 = digitalRead(button_1);
button2 = digitalRead(button_2);
button21 = digitalRead(button_21);
button22 = digitalRead(button_22);
digitalWrite (light_1,LOW);
digitalWrite (light_2,LOW);
digitalWrite (light_21,LOW);
digitalWrite (light_22,LOW);
digitalWrite (l1,LOW);
digitalWrite (l2,LOW);
digitalWrite (l3,LOW);
digitalWrite (l4,LOW);
digitalWrite (l5,LOW);
digitalWrite (l6,LOW);
digitalWrite (l7,LOW);
digitalWrite (l8,LOW);
digitalWrite (l9,LOW);
digitalWrite (l10,LOW);
digitalWrite (l11,LOW);
delay(100);
digitalWrite (l7,HIGH);
delay(100);
digitalWrite (l8,HIGH);
delay(100);
digitalWrite (l9,HIGH);
delay(100);
digitalWrite (l10,HIGH);
delay(100);
digitalWrite (l11,HIGH);
delay(100);
game = 0; //resets game state
}
}
Now that you’re done coding, its time to make sure everything works. If everything works, make sure your solder is connected. If you used a protoboard, its now time to tape/glue/screw that in place. Turn on your Arduino using the power switch, close your box/enclosure/case and enjoy your game.