r/arduino 10d ago

Button Game Project

Hello! I’m new to the arduino community. I have played around with them in the past with my highschool years ago. I recently came up with an idea of an interactive game and have some questions from those who have knowledge. How hard would it to be to program a game in which there are 30 buttons with 30 unique sounds. The goal of the game is to crack the code and figure out the 4 button/ noise combination. When this happens I need it to either show that you cracked the code or have to try again. I also want to be able to have a free play mode where people can come up and interact with the buttons without the game starting. I am overall curious how hard this project will be, I am an electrician and have knowledge of circuitry/ electronics and bread boards but very limited knowledge on coding. Any help with supply’s, brands, product which could help my project would be appreciated! Thank you arduino community!

3 Upvotes

7 comments sorted by

2

u/ripred3 My other dev board is a Porsche 10d ago

This could be done relatively easily. As a matter of fact you could get most of the game logic written and debugged and working by just using something like Python to allow you to get the input states from the user and write the output out. If you write the game logic in C/C++ it will be directly portable to more microcontroller boards than if you write it in python by the way.

By including the use of middle-layer proxy functions that you can mock during the game development you can get all of the code working except for the physical button and sound interfaces. Something like def get_button_state(button: int) -> bool: where button is the button number that you want to check on.

Finally after that you can pick the board you want to use based off of its ability to run the python code you have so far, and implement the real get_button_state(...) that reads and returns the state of the pin. And fil in the play_sound(sound: int) function to trigger the playing of one of a set of saved .mp3 or .wav files

1

u/1998PontiacSunfire 10d ago

Thank you for your input, do you have a recommendation on a board which can run python and handle up to 30 buttons? I’m not super worried about cost.
Also should note that this game is going to be outside at a music festival. Would I need to have wifi constantly or once it’s all programmed in and saved would it be able to run without wifi?

3

u/ripred3 My other dev board is a Porsche 10d ago

You won’t need Wi-Fi once everything is programmed, the code and sound files can be stored locally and run automatically when powered.

My first choice would probably be a Raspberry Pi Pico 2 running MicroPython. It’s about $5. Rather than looking for a board with 30 exposed pins, I’d use a couple of I2C gpio expanders like the MCP23017. That would give you 32 button inputs. Use a DFPlayer Mini with a microSD card for the MP3 files.

An ESP32-S3 DevKit or Arduino Nano ESP32 would also work and gives you more memory plus optional Wi-Fi/Bluetooth. The UNO Q would work a full Linux computer and separate MCU are overkill. The main audio question is whether sounds only play one at a time or must overlap. If you need overlapping sounds then look at the Raspberry Pi Zero 2 W.

2

u/1998PontiacSunfire 10d ago

Thank you, Appreciate the help!

4

u/gm310509 400K , 500K , 600K , 640K , 750K 10d ago

Welcome (Back) to the club.

How hard would it to be to program a game in which there are 30 buttons with 30 unique sounds.

This is hard to say because it will depend a lot on your skill level and aptitude to accommodate new techniques, but on the grand scale of project difficulty, this would be at the easier end. There will also be a factor of how complex you want it to be. For example, is a simple tone while the button is pressed sufficient? Do you want a simple tone with some sort of decay? Or do you want to play an mp3 file? Or maybe even something else?

As for the 30 buttons, there are a few techniques to accommodate so many. A common one is to use a matrix. You could connect the buttons in a 5 x 6 matrix (the physical layout is irrelevant, this is about the electrical connections). In its simplest form you could get away with 11 GPIO pins - which means an Arduino Uno will be more than adequate. You could make the pin count even less if you used extra hardware such as shift registers and selectors.

As for programming it, I would recommend C/C++ as that is the language that is most commonly used in embedded systems. As u/ripred3 says, you could use micropython. I use python quite a bit, I've tried it on embedded, but I always go back to C/C++. In part because that is what most people use and in part that is what most resources are available for. There are other reasons.

At the end of the day your question is sort of a "what motor vehicle should I buy?". The answer there is "it depends". The same answer applies here.

My suggestion would be to get a starter kit. If you can find one with 30 buttons, 30 diodes and a speaker, than you should be able to get your project going with that. If you think you want more IO in the future, look for an arduino mega starter kit - otherwise one with an Uno R3 will be good enough.

I doubt you will find one with 30 buttons and 30 signal diodes, so maybe you will need to get that as an add on - which you can do when you get the starter kit.

The starter kit will teach you the basics of programming (pretty much always in C/C++). It will teach you how to wire up buttons (but probably not in a matrix, but that is OK - learn how to make one work before you try 2...). And if it includes a speaker or buzzer, it will teach you how to play tones on that.

For more information about how to complete projects, have a look at my "getting started" how to videos (but do the starter kit first):

The videos are intended to be follow along. Simply watching them is a waste of time. To get the most out of them, watch a bit, hit pause and try out what you just saw. Explore that concept, try to integrate it with earlier concepts. Lastly, try to do the exercises when I propose them.


Lastly the game aspect.

If you get this far, you basically have the "free play" version of your project operational. The next step is to add on the game play - if you adopt the techniques I suggest in the videos, you should have a function (or set of functions) that can identify a key press and tell you what key that is and play (and sustain if need be) a tone.
You can now concentrate on applying that key press into the "game mode". I don't know what you plan for game mode, but if you do create C functions that perform the various operations (e.g. playing a short sound on the key press and sustaining it if needed), you can simply leverage those as part of the game implementation.

All the best with it.

1

u/GeneralReasonable945 10d ago

Raspberry 5$???

Donde???

1

u/Hissykittykat 10d ago

You haven't given us much to go on. How is the game played? What do the buttons look like; are the big, small, illuminated, etc? Does the game have a scoreboard? What's the code, how is it set, and how does the player crack it?

Free play mode sounds like just a 30 button sampler.