Multi-player SIMON
This project was inspired by the CLASSIC Simon game, and by the MODERN app "BeReal".
Inspired by these 2 time-spanning mega trends we have decided to fuse them into a fun, easy 2 player multi-player game that can be played remotely with each other.
Watch the video before you go.
Supplies
Connect CPX to ESP8266
Connect the CPX's to your Wi-fi ESP8266 boards by following the image above.
Run the sketch attached.
Open the Serial Monitor and type the command : "AT+RST".
Make sure the output is as the image attached (cpx-esp8266 output).
If you get a different output, update your firmware version using the esp8266 guide :
https://www.espressif.com/en/support/download/other-tools
or update the version from this direct link and run the Download Tool:
http://bit.ly/esp-firmware-174
Downloads
Learn the Game
How to play:
* When started the CPX will sound a theme and light with white leds.
* Followed by the first round, blue leds will light up showing you which numbers are in the sequence (number of leds = digit to click).
* Click the digits in the right order and watch the CPX receive them.
* The number of digits increase each round by 1 and the sequence is generated randomly.
* Your score will be composed of the last level you passed, and the time it took you. Better level will always win, and in case of a tie, best time will prevail.
* You shall pass 10 rounds to win the game!
Creating the Sketch
Download the attached file sketch "final_project.ino" into your computer.
Inside the sketch - edit the wi-fi information: network name and password.
Downloads
Creating Blynk Template and Devices
Templates (inspect image "templates")
The template is based on five virtual pins that maintain the interface between the board and "make" site as follows:
1. V0 - Starter in - receives the value 1 via an http request from "make" website, which update it when a "starter scenario" is activated by the opposing player. The CPX reads the V0 data while the game is not active, and starts the game when it detects an update of the pin data.
2. V1- Score - receives integer data from the CPX about the score of the last game played. The pin is connected to a webhook on "make" website which triggers the "Main scenario" sequence of events as described below. The pin receives values between 100,000 and 210,999 which "make" processes into data about the game played (player name, stage and game time).
3. V2 - Starter - receives data from the CPX, after pressing the right button. When the user presses the right button on the CPX, the pin will change its value from "1" to "0" and vice versa. The pin is connected to a webhook on "make" website which activates the sequence of events for the "Starter scenario" as described below, at the end of which the value of the V0 pin changes on the opposing player's device.
4. V3 - Scream - After breaking a record, the user is required to scream with joy for 5 seconds. The strongest measurement of the cheers is sent as an integer data to pin V3, which is updated accordingly. The pin is webhooked to "make" site, which triggers the "Send scream scenarios".
5. V4 - High Score - After each game, the "Main scenario" is activated on "make" site. If a new record is broken, the scenario will update V4 via an http request (receiving the value 1). The CPX, which has just finished a game, reads the data of V4, and if it detects a change, it will trigger the sequence of events in the code that will start the recording of the scream, and the lighting of the board.
Devices (inspect image "Devices")
On "Blynk" website, we will create two devices based on the same template as described in the previous section. Each device receives data from a different user's board, and transmits its data through different webhooks to run scenarios on "make" website.
Webhooks (inspect image "Webhooks")
The webhooks are divided into three groups with different roles, where in each group there are two links to pins that are identical in number, but different in device:
- "Game Starters" - are connected to V2 each on their device, and start the process of "Starter scenarios" on the opponent's CPX using "make" site.
- "Score senders" - are connected to V1 on their device, and starts the "Main scenario" process by sending the result data to "make" website.
- "Scream senders" - are connected to V3 on their device, and starts the process of "Send scream scenario" by sending the input data from the scream to "make" website.
Dashboard (inspect image "Dashboard")
The dashboard view reflects the user status of each pin in the device, and what values it is receiving and transmitting. The display of all pins except V0 is "label" display, a "string" data of the current value in the pin. We present V0 as a switch that enables us to distinguish easily if a change was made as a result of pressing the right button on the opponent's CPX.
Creating Make.com Scenarios
Main scenario:
- Webhook trigger - new score arrived in Virtual pin V1 of one of the CPX's.
- Google sheets - get cell H1 - current highscore.
- Google sheets - add a row. Coding the score as follows:
- each score is a number in range 100,000-220,000
- left-most digit represents the player that posted the score - 1 / 2 accordingly.
- tens of thousands (0-10) represent the level reached.
- hundreds (0-999) represent time in seconds.
- decoding the score is processed in this make.com scenario, so in the scoreboard only the processed date is posted. the lower the score, the better it is.
- Google sheets - update cell K1 - latest score posted.
- Google sheets - update cell F1 - player number that posted that score.
- Google sheets - get cell K1.
- Google sheets - get cell F1.
- Router - reached if and only if highscore is broken. This is done with a filter before the router with the condition: K1 > H1. The router navigates the flow to the right sequence of modules according to the player that posted the new highscore. Each time, only one of the paths will be active since only one player can break the record at a time. Deciding to which path will continue the flow is done by 2 filters positioned after the routed checking the value of F1. If F1 is player 1, the bottom path (modules 9-11), else the higher path (modules 12-14) will be active.
- HTTP request - update Virtual Pin V4 (highscore) in CPX 1 to value 1 representing player 1 broke the highscore.
- HTTP request - update Virtual Pin V4 (highscore) in CPX 2 to value 1 representing player 1 broke the highscore.
- Telegram -
- set up a telegram bot (here's a link to a specific great tutorial)
- create a telegram channel and subscribe to it from both players, and from the bot.
- the module sends a message to the channel "Player 1 broke the record. He reached level x in y seconds. Time to shout!"
- HTTP request - update Virtual Pin V4 (highscore) in CPX 1 to value 2 representing player 2 broke the highscore.
- HTTP request - update Virtual Pin V4 (highscore) in CPX 2 to value 2 representing player 2 broke the highscore.
- Telegram - same setup as module 11 - sends a message to the channel "Player 2 broke the record. He reached level x in y seconds. Time to shout!"
Starter scenarios:
- Webhook - Virtual pin V1 (activate opponent) value updated in CPX 1.
- HTTP request - update Virtual pin V0 (start game) in CPX 2.
- Webhook - Virtual pin V1 (activate opponent) value updated in CPX 2.
- HTTP request - update Virtual pin V0 (start game) in CPX 1.
Send scream scenarios:
- Webhook - Virtual pin V3 (volume) value updated in CPX 1.
- Telegram - send message with max volume detected.
- Webhook - Virtual pin V3 (volume) value updated in CPX 2.
- Telegram - send message with max volume detected.
Getting to Know the Scoreboard
Link to the Google Sheets file. Clone the file.
Now update all the Make.com scenarios you created: update the Google sheets modules to operate on the file you have created.
Update Sketches Accordingly
Update the sketches:
- insert the blynk tokens according to the tokens provided by the blynk app.
- update the send score function:
- player 1 sends {score + 100,000}
- player 2 sends {score + 200,000}
- BLYNK_WRITE(V4) function -> if condition:
- player 1 : if (high_score_broken == 1)
- player 2 : if (high_score_broken == 2)
Play, Win, and SHOUT LOUDEST!
Load the sketches to the CPX's, and run the make.com scenarios.
Now each player can challenge the other by clicking the left button, activating their CPX with the game.
Challenge each other once a day, and try to break each other's records.
Have fun!