Micro: bit

Micro:bit & Rock Paper Scissors

By July 26, 2017 No Comments

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.


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.

Our Requirement:

    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.

Materials Needed:

Micro:bit ×2
USB Cable ×2

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 2:

Set the function of button “A”. Every press changes pattern order.

We use pattern to show rock, patternto show scissors, and pattern for paper.


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 4:

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


Step 5:

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.


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


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 Micro:bit Adapter

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

 

VN:F [1.9.13_1145]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
Micro:bit & Rock Paper Scissors, 10.0 out of 10 based on 1 rating
song

Author song

More posts by song

Leave a Reply