The Two Button game started as an exercise in portable game development and turned into a multi-player, multi-device experience which uses two Connected Little Boxes to both display the pixel puzzle (determine whether there are more red lights or blue lights) and allow the players to enter the answer (a red button and a blue button).
You can find the code for the game and circuits for Raspberry Pi, ESP32 or Raspberry Pi PICO here. The game code includes a version that runs as a server and hosts the game over MQTT for two devices. All the devices must be connected to the same MQTT server. You will need to enter the MQTT server details along with the addresses of the red and blue boxes into the program file.
The game users two controller boxes that each contain a 12 pixel ring and a push button. You can find the design for the controller boxes and the circuit diagrams here.
Each Connected Little Box has an unique address which can be used to locate it via MQTT. You will need to obtain the address of each box so that the server can send messages to that box. The "red" button box will have one address and the "blue" box another. The setting mqttdevicename holds this address and you can view its value just by entering its name:
"mqttdevicename"
The boxes will need to be configured to send messages to the server when their buttons change state. We will set the address of the server in the next section. In the sample code below the address used is clb-host. Pick the name you want to use and put that in the command in corect place (the "to" attribute)
{"process":"console","command":"reportjson","text":"starting","attr":"button","sensor":"button","trigger":"changed","to":"clb-host","store":"mqtt","id":"button"}
Be sure to type this correctly. The best approach is to copy the above command and paste it into Notepad, and then copy and paste the text into the Simpleterm command. Note that it must be entered as one line.
The server code can run on any machine that supports Python 3.n. Ensure that you have installed the Paho MQTT library before running the code. The program must be configured with the mqtt device names used by the two Connected Little Boxes that will be used as game controllers. From the previous step you should have the names of the two controller boxes. Add them into the code in the positions shown on the right.
The mqttdevice setting for the server is the name that the boxes will use to send button pressed information to the server. The red_button and blue_button settings are the addresses of the boxes that will be sendign button information to the game server.