Introduction: Micro:bit & Rock Paper Scissors

About: Email: louise@elecfreaks.com

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.

Note:
For more funny creation, you can pay attention to : http://www.elecfreaks.com/

Our product store: http://www.elecfreaks.com/estore/

Step 1: Our Purples of Writing

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 2: 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 3: Function to Realize:

1. Press button “A” to choose Rock, Scissors or Paper.

2. Press button “B” to confirm our choice and transmit it with Bluetooth.

3. 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 4: Materials Needed

Micro:bit ×2

USB Cable ×2

Step 5: Programming*step 1:

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 6: Programming*step2

Set the function of button “A”. Every press changes pattern order. We use pattern "X" to show rock, pattern "k" to show scissors, and pattern "口“ for paper.

Step 7: Programming*step3

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 8: Programming*step4

Set Bluetooth receiving function. Store the received data into variable “receiveNumber”, and set”received” to “1”.

Step 9: Programming*step5

Judge in “while” circulation. Once we showed our choice, then it will start to judge who wins. Usually we use to show " √ " victory, "X" for lose, and " ◊" for tie.

Step 10: Programming*step6

Then, let’s download the code into micro:bit and see what will happen.

You can download code here directly.

Step 11: 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.

Relative Readings:

Elecfreaks Micr:bit Adapter

How Micro:bit works with Octopus? We made a Raining Alarm demo

Note:
For more funny creation, you can pay attention to : http://www.elecfreaks.com/

Our product store: http://www.elecfreaks.com/estore/