Close
0%
0%

Project Battlesnakes

A classic game of snake, but with a twist and added hardware constraints.

Similar projects worth following
Who didnt build some sort of snake game as an electronics beginner? A led matrix, a controller and some buttons. So why not remix this timeless classic for the tiny games challenge?
Its always fun to redo an old beginner project with some added experience. Maybe we even learn a thing or two on the way.

BUT to make things a bit more challenging: Lets add some constraints.
1. No modules or shields.
2. Make it portable.
3. Stay around ~10€ for BOM.
4. No Exotic packages.
5. Obtainable hardware.

And most importantly

6. Make it multiplayer. Whats more fun than to challenge a friend? Will it be to settle disputes, duel over who pays the next round, or just to establish dominance.

A mixture of Snake and Tron. Its a fast chaotic short game for a relative low cost.

It runs on two AA Batteries, uses standard components and is quite easy to build (if you have some SMD skills)

Please read the project logs (will be updated) if you want to see some development details.
The game is base on a ATmega168, so you will need an AVR programmer. The PCB is done with KiCad.

Its using dual colored LED´s to distinguish between the players. Other than that its classic snake, pretty much self explainatory.

Did i manage to finish the project in time?

Hell yes!

Did i manage to keep the BOM at my targeted 10€?

Sort of ...

Feel free to download, rebuild, improve or whatever. But let me know if you do something cool :)

Have fun!

PCB.zip

x-zip-compressed - 296.22 kB - 09/03/2024 at 06:57

Download

Software.zip

x-zip-compressed - 2.48 kB - 09/03/2024 at 06:57

Download

View all 9 components

  • Final thougts

    Phil Weasel09/03/2024 at 07:45 0 comments

    The contest gets to an end and there is unfortunately no time to make any hardware improvements.
    But i think it turned out pretty well. Game is working on two AA batteries and the BOM is quite low.

    Also its reusable for any future software/game project : )
    Lets see what the future holds.

    Only thing i can improve for a next version would be:
    Ditch the power button and make it sleep/wakeup on a button push -> Save 0,56€
    Replace the two battery holders with a single one for two batteries -> Save 1,30€
    -> New total cost of ~10,74€

    Maybe add some additional Caps for protection. They cost almost nothing ...

    However.

    If you decide to use this project as a base: Have fun :D

  • Game logic

    Phil Weasel09/03/2024 at 07:34 0 comments

    We can now show something on the screen. Lets write the game 

    -> You can find the game logic in the main.c

    The game logic itself is pretty much straight forward but with one twist:
    For the playing field every LED is numbered (0-63, bottom left = 0, top right =63) and every LED got an signed integer. (so its a 64Byte array)

    This way the head position of each player is just a number instead of coordinates.
    Moving up = position +8, down -8, left -1, right +1

    Also the reason to use a signed integer:
    Positive value = Player 1
    Negative value = Player 2
    -> Storing both players in one Array saving some data.

  • Driving the LED´s

    Phil Weasel09/03/2024 at 07:26 0 comments

    The LED´s are controlled row for row.
    Every row is two bytes, one for RED, one for GREEN (= 16Led per row -> 16Bit)
    So we have a screen buffer of (2*8Bit)*8Rows = 16Bytes

    Displaying frame therefore consists of:
    1. Combining RED and GREEN buffer of current row to a 16Bit integer
    2. Sending the 16Bit via Data pin
    3. Pulling LAT HIGH(driver will output last data received)
    4. Pull PNP Transostor of corresponding row LOW
    5. Wait for a ON-time
    6. Pull NPN HIGH
    7. Pull LAT LOW
    8. Repeat for every row

    Since this is happening so fast, the LED´s are in fact blinking, but since our eyes are so "slow" we see it as a constant on.

  • Soldering time

    Phil Weasel09/03/2024 at 06:39 0 comments

    Well, *german shipping company* somehow lost my package. But thanks to the incredible guys from Aisler i still got some new PCB´s just in time.

    Turned out quite nice. I somehow managed to order the wrong powerswitch so i had to use a substitute.

    Lets get programming.

  • First calculation

    Phil Weasel07/29/2024 at 20:27 0 comments

    While im waiting for the pcb, i ordered the parts on digikey and did my first calculation.

    For the other components i did not crunsh the numbers as much. The reason being: im just a lazy bum.


    Parts list so far:

    LED, 64x 0,078€
    Atmega168, 1x 1.36€
    AA Battery holder, 2x 1.30€
    0805 Capacitor, 8x 0.063€
    0805 Resistor, 17x 0.034€
    PNP BJT, 8x 0.065€
    Driver, 1x 0.56€
    Pushbutton, 8x 0.115€
    Powerswitch, 1x 0.56€

    = 12.60€

    Well a bit over the hoped outcome.

    In hindsight there a a few points i could have done better:

    I used a AA Battery holder, just using clips or coin cells would cut the cost of them by half or 2/3.
    Ditching the Buttons and go for capacitive touch. (I didnt dare to for the contest because i never tried it)
    Maybe i can even find a row-driver?
    Programming the game will let me see if i can go for a smaller controller.
    Heck you could even ditch the powerbutton. Just use the sleep mode and wake him up with a button and ......

    But first things first, im getting ahead of myself. Lets make get the first version to work....

  • Prototyping time

    Phil Weasel07/29/2024 at 20:01 0 comments

    Two long evenings later, a layout was born and a first prototype ordered.

    Well first prototype is nice to say, considering the short time available it will propably be the final version.

    The rest of the circuit is pretty straightforward. WIth the shift register i managed to have only 2 free pins left (besides the programming pins). Also the driver/register has this nice function that it limits the current for us. No need for resistors, some cents saved.
    Oscillator? No need, internal is good enough.
    Voltage regulator/supervisor? No need, input range of the components is wide enough.
    It would be possible to multiplex the inputs too but there is no need here.
    In hindsight the only critical thing i forgot for now would be a diode for reverse polarity protection.
    But that would bring down the already low 3V from the planned AA batteries. Which reminds me that the driver wants a VCC of 3V-5V.
    Quite Exciting. The datasheet does not mention any undervoltage lockout. Will it work? Only the first assembly will show.

  • How to control those LED´s .....

    Phil Weasel07/29/2024 at 16:35 0 comments

    Ok so after selecting the type of display i want to use we have one problem.

    8 rows + 8 columns red + 8 columns green = 24 pins i need for the controller

    Adding 8 buttons brings us to 32 needed IO pins .... too much for the average ATMega i want to use.

    Now what?

    Enter: Shift registers for LED´s

    Now we can control a whole column by a serial interface. But why 16 bit you might ask? Well, we can split the register into 8 red and 8 green. So we can control both colors per row at the same time in one go.

    Also we can ditch 16 transistors. Looking at the cheapest i found at this time we effectively even save half a euro (1,04€ for 16 Transistors VS 0,56€ for 1 driver)

  • First Ideas

    Phil Weasel07/29/2024 at 16:15 0 comments

    First thought is obviously on what to use as a display. Modules are first too expensive and second against my own rule.

    So whats left ... 7 segment display? The LED´s look like snakes so it might be a fun idea. But no.

    Since i want to make it a two player game, i might want to add some color to distinguish between the players. So RGB LED´s it is. But there are two problems. Affordable ones are in crazy small packages, and programmable ones are too expensive.

    Enter: Dual Color LED´s.

    these to be precise

    They might not be as fancy, but do the job for a bit lower price. Also with the added advantage of having one pin less which will be useful later.

    For size i settled for a classic 8x8 matrix. Increasing the playfield just increases the cost exponentially and this feels OK.

    Maybe something for another project.

View all 8 project logs

Enjoy this project?

Share

Discussions

Does this project spark your interest?

Become a member to follow this project and never miss any updates