"It’s Here! The BFCM Sale of the Year – Grab Your Favorites!"

Micro:bit & Rock Paper Scissors

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, pattern

to 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

Leave a Reply

images
In March, ELECFREAKS supported 5 schools to carry out school science and technology festival activities
images
Children’s Programming Education is the Future Trend
images
Technical verification! Nezha series products can complete WRO competition tasks
images
Let's take part in the Ceremony of the New Factory of ELECFREAKS together!
images
Bluetooth Bee(HC-05 and HC-06) User Guide
images
In March, ELECFREAKS supported 5 schools to carry out school science and technology festival activities
Monthly Archive