Twang32 is an adventure game placed on a long line of luminous points which in this case is an Led strip with WS2812 Leds. With the help of a flexible joystick, the player must moves his character, one of the LEDs, in a one-dimensional line world. The player will have to overcome obstacles and face enemies in order to find the exit. The game is played on a 1000 unit line, the position of enemies, the player, lava etc range from 0 to 1000 and the LEDs that represent them are derived using the getLED() function. Regardles of the number of LEDs, everything takes place in this 1000 unit wide line.
This project is inspired by Line Wobbler game by Robin Baumgarten, and the original GitHub page is:
I made small modifications by making a custom case, and I use a spring that I managed to find in my workshop. The downside is that the LED strip takes up a lot of space which is quite impractical, as a standard LED strip can contain up to 144 LEDs per meter. For this purpose I use the RGB Programmable LED Strip from DFRobot (https://www.dfrobot.com/product-2255.html?tracking=61ee19d8ddc08) which contains 166 diodes with a length of only 50 centimeters and is compatible with WS2812B strip. The extra space required is reduced by the strip extending at an angle of 60 percent upwards after half its length.
The Controller uses a spring, and an accelerometer and is surprisingly precise joystick with a unique 'wobble' action (pull it back and let go to make it oscillate back and forth rapidly). It is this wobble action that is core to the experience while game playing.
As I mentioned before the device is very simple to build and contains only a few components:
- ESP32 based microcontroller board
- PAM8403 small D-class amplifier board
- MPU6050 - 6-axis Motion Tracking device which is located at the top of the joystick
- And an LED strip that can contain from 60 to 1000 LEDs. In this case it contains 166 Leds, which is quite a sufficient number for comfortable playing.
First we need to compile and upload the firmware using the Arduino IDE. This procedure has been explained many times before, so now we will present the basic steps. In order to do that, we need to install Arduino Core for ESP32, and than FastLED and RunningMedian Libraries. Now download the TWANG32 Sketch Source files, and all of the files should be placed in a folder called TWANG32. You need to uncomment in config.h (remove //) in front of the line for the strip type you have. Make sure only one of the #define lines is uncommented. Next open the settings.h file in the same folder as TWANG32.ino. Change the #define NUM_LEDS 166 to the LED count you plan to use. This sets the default number of LEDs in your strip. After that, to the following steps to compile and upload the firmware. This could take several minutes to compile.
- Under the Tools…Boards menu, select the ESP32 dev board
- Connect the ESP32 to your computer.
- Select the correct com port from the Tools…Port menu.
- Click on the Upload button.
And now let's see how the device works in reality:
The game consists of 20 levels where each subsequent level is more difficult than the previous one. By moving the joystick forward/backward, the green (player) diode also moves. The speed of movement increases in proportion to the increase in angle. If we tilt the joystick side-to-side or wobble it, the weapon that destroys the enemy is activated. If you take a closer look at the code, in the "void loadLevel" section there is a commented tutorial for editing or creating new levels of your own.
The game also has a WiFi access port to get game stats. We need to connect a smartphone or computer to see them.
You can update these settings over WiFi
Joystick Deadzone (removes drift)
Attack Threshold (twang sensitivity)
and Lives Per Level
Unlike the original, where the box is made on a 3D printer, I mounted it in a suitable box made of PVC board with a thickness of 3 mm because for me it was a simpler solution.