Introduction & Brief
We were asked to create a game based only on an arduino card, which had to be autonomous once plugged into an AC outlet. We had the mission to make the game as fun and original as possible from a few components. The objective was not to build a complex game, but to find the right idea: simple and effective, then to realize it with particular attention to the small details. (graphic environment, how the game rules were explained, ranimations between the parties etc.)
What is Arduino?
A team of developers composed of Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, David Mellis and Nicholas Zambetti who imagined a project answering to the soft name of Arduino and implementing a small programmable electronic board. A multiplatform software, which can be accessible to everyone in order to easily create electronic systems. Considering that there are beginners among us, let's start by seeing a little bit of the common vocabulary specific to the field of electronics and computer science.
To carry out this project, we made a list of materials that we used during our realization:
- 1 Arduino Uno card.
- 1 USB cable.
- 1 breadbord and cables.
- 3 push buttons.
- 4 resistors (3 x 1K and 1 x 10K).
- 1 matrix of 8 x 8 LEDs (64 LEDs).
- 1 digital counter (1 5v power supply).
ASTRO is an electronic game mainly inspired by Flappy Bird games where the gameplay is based on the agility of the player, who must move a bird in a horizontal scrolling environment by tapping on the touch screen, while avoiding pipes at the top and bottom of the screen. The goal is therefore to avoid the pipes and to go as far as possible. Another inspiration that helped us is an older game called Space Invaders where the principle of the game is to destroy waves of aliens with a laser gun by moving horizontally on the screen that descends little by little. There is also the Frogger game, which aims to lead frogs to their homes. To do this, the player must first cross a road by avoiding cars that travel at different speeds and then a river with changing streams as they pass from objects to objects. The frog dies if it touches a car or falls into the river.
Your planet is about to explode. You have to flee aboard your spaceship but you face a big obstacle... Indeed, the asteroid belt will not let you pass so easily. Visitor of the space I wish you good luck. Over.
Here the player must move his ship horizontally with two buttons (right and left) and must avoid asteroid walls by passing through the available hole(s). The goal is therefore to think carefully about its movement, which will be more and more dynamic to pass through the entrance of the walls. It will require agility and good reasoning. The ship has 2 shield barriers if it is hit a third time by an asteroid, it explodes, which will inevitably happen.
Some test codes
To realize this project, we will use 5 libraries that will make it easier for us to use the buttons, the piezo buzzer, an 8 x 8 LED matrix and a 3 LED ribbon.
First of all, we install the 3 buttons, one to go left, one to the right and the last one that we place in the middle to reset and start the game again.
NeoPixel, NeoMatrix and GFX libraries
Concerning the led ribbon, we will use a NeoPixel ribbon offered for sale by Adafruit. The product and the library are extensively documented on learn.adafruit.com : there are assembly instructions and explanations on how to use the library. This is also available in the library manager.
For the 8 x 8 x 8 LED matrix, we will use the libraries Adafruit_Neopixel, Adafruit_GFX, Adafruit_NeoMatrix. They are available in the library driver of the Arduino IDE and incorporate basic examples.
These are libraries that allow easy and efficient control of a wide variety of LED Matrixes.
Like all libraries in Arduino, we start by including it at the beginning of the program, so before setup() :
The same procedure applies to the NeoMatrix library:
While initializing the colors of the ribbon:
In the setup() :
We also initialize the part for the NeoPixel library:
Warning, it is strongly not recommended to use setBrightness() to vary the LED light intensity in the loop(). The brightness is to be defined only once, in the setup().
For example, to switch on a blue led:
Or, to switch them all on in red:
And to turn them all of:
By default, we try to use as little strip.show as possible, usually we place it at the very end of the loop().
The FastLED library
When you press a button once, it increments a value specific to each button. The values are displayed in the serial monitor.
Concerning the 8 x 8 x 8 LED matrix for the creation of descending walls, we will use the FastLED library. They are available in the library manager of the Arduino IDE and incorporate basic examples.
These are libraries that allow easy and efficient control of a wide variety of LED Matrixes. In addition to writing on the LEDs, this library also includes a number of functions to perform high-performance 8-bit calculations to manipulate RGB values. Tested with Arduino up to 1.6.5 from arduino.cc.
Among other things, they allow you to easily manage the LEDs on the 8x8 matrix ether 64 LEDs.
Like all libraries in Arduino, we start by including it at the beginning of the program, so before setup().
The library notes.h:
The library allows you to define all the notes to make a melody. Like all libraries in Arduino, we start by including it at the beginning of the program, so before setup()
Then always before setup(), we declare the Pin on which is the piezo buzer and we define the number of notes, the duration of the notes and the notes to play in the melody:
In the setup() the piezo pinMode (SPINDLE_HP, OUTPUT) is initialized;
The final assembly
The framework of the game
In order to finish our game well, we decided to create a wooden box that looks like a Gameboy. The box is tilted to ensure that it can be played directly on the table or in the hands. We also named our game "ASTRO" because at first glance we see the led that we direct little closer to a ship and therefore that must avoid the asteroids that fall. This is also why the box is painted in night blue.
Design of the box
The box was made of wood. The cuts have been made with laser cutting in order to have an irreproachable precision. After this we applied several coats of blue-night paint for the aesthetic side of the box.