Rock Paper Scissors, you might know it well for you had played it in your childhood again and again. No matter how fairness it seems, this game has drawback, which comes from your hand motion speed and tricks,and you must have observed if you paid attention to it. We all know that BBC micro:bit has Bluetooth function and different micro:bit boards can transmit data with it. Today we are going to use this Bluetooth function to play Rock Paper Scissors. Bluetooth signal is unseen and untouchable so that it will completely eradicate tricks during the game.
Step 1: Our Goal:
Through studying the case i am going to show you, you can gradually get to know the usage of micro:bit Bluetooth function such as Group ID setting, data transmission and data receive.
Step 2: Our Requirement:
Press button "A" to choose Rock, Scissors or Paper.
Press button "B" to confirm our choice and transmit it with Bluetooth.
If we have finished choose and received data transmitted from our partners, then micro:bit will begin to judge who wins and display it on the panel.
Step 3: Materials Needed:
USB Cable ×2
Step 4: Programming:
Set different Bluetooth group ID. Here we set group ID to be 13. Only if two micro:bit board have same group ID, then Bluetooth communication can be done.
We use button "B" to confirm. Set button to "0", means we do not press button while set to "1" means button pressed down.
We set variable " received" to show it has received Bluetooth signal. "0" for not-received and "1" for received.
We use variable "item" to preserve our hand signs. "0" for rock, "1" for scissors, and "2" for paper.
Step 5: Programming:
Set the function of button "A". Every press changes pattern order.
We use pattern to show rock, patternto show scissors, and pattern for paper.
Step 6: Programming:
Set the function of button "B". With Bluetooth signal, we can send out our hand signs(i.e. variable "item") At the same time, set button to "1".
Step 7: Programming:
Set Bluetooth receiving function. Store the received data into variable "receiveNumber", and set"received" to "1".
Step 8: Programming:
Judge in "while" circulation. Once we showed our choice, then it will start to judge who wins. Usually we use to show victory, for lose, and for tie.
Step 9: Result
Then, let's download the code into micro:bit and see what will happen.
Step 10: Question:
If we want to show rock, scissors, or paper randomly, then how shall we change our program? For more interesting postings, you can follow up our blog or leave your comments.