We are all familiar with the game Rock Paper Scissors. Let's take a look at how we can code our micro:bits to play
What You Will Learn
How to create and use a variable.
How to use the micro:bit on shake function.
How to display images/shapes on the LED matrix.
How to use conditional if/else statements.
How to use comparison operators.
How to randomise choices.
What You Will Need
1 x micro:bit
1 x micro USB cable
1 x battery pack for the micro:bit (optional)
Coding
What is a variable
Think of a variable as a box that stores information that can be used throughout our program. We give variables a descriptive name so we and others can understand what is going on within our program.
Within your favourite browser (we recommend Google Chrome) go to python.microbit.org and press enter. This will load the MicroPython coding editor.
Delete the text on lines 6-8.
Click on line 3 and type import random.
Click on line 6 and type the following code:
Completed code:
We have now finished coding rock paper scissors the next step is to download our code to the miro:bit.
Downloading the Code
Take the micro USB cable and connect the micro:bit to the computer.
Click on Connect.
Click on your micro:bit and click connect.
Click Download.
You have now successfully coded a micro:bit to play raock paper scissors.