Lesson 2 Programming with micro:bit

LESSON 2 – Introduction to programming with micro:bit

Lesson Objectives

  • Introduction to programming with micro:bit

Success Criteria

  • must decompose a problem to solve it using Computational Thinking with micro:bit programming
  • should demonstrate skills to use an algorithm to do something with their micro:bit
  • could show skills and knowledge to create a game with the micro:bit

Keywords

  • Algorithm
  • Selection
  • do while
  • Compile

Commands

  • on shake
  • random
  • set img
  • run / compile

Starter

Complete your starter activity in silence

In this lesson you will be creating a ROCK, PAPER, SCISSORS game in micro:bit. The paper designed for you how it should appear on micro:bit.
Now it is your turn to design Rock and Scissors on the below grids.

If you are not given on paper answer the following questions in your books

  • How many LEDs are there on a micro:bit?
  • How many touch buttons are there?
  • Is the micro:bit a full computer?

Read the information on this link to help you answer above questions.
Use this link if you would like to find out more information about micro:bit

Task 1 – Rock – Paper – Scissor game

We want the BBC micro:bit to choose rock, paper, or scissors when it is shaken. Let’s begin by creating an on shake condition so the micro:bit will run code when it is shaken.

Next, create a variable and store pick random number from 0 to 2. On shake, a number will be randomly picked from 0-2. We will randomly display an image based on the random number returned.

The BBC micro:bit will look like it’s showing 1 frame of the image by displaying the whole image when pick random is equal to 2. We can help the BBC micro:bit randomly decide which image to use by pick random. The BBC micro:bit will randomly pick the image to display with show LEDs and the pick random function.

The BBC micro:bit will look like it’s showing 1 frame of the image by displaying the whole image when pick random is equal to 1. We can help the BBC micro:bit randomly decide which image to use by pick random. The BBC micro:bit will randomly pick the image to display with show LEDs and the pick random function.

The BBC micro:bit will look like it’s showing 1 frame of the image by displaying the whole image when pick random is not equal to 2 and not equal to 1. We can help the BBC micro:bit randomly decide which image to use by pick random. The BBC micro:bit will randomly pick the image to display with show LEDs and the pick random function.

Well done! You have finished your program. In your book explain the random function what does it do in this program?

Task 2 – Compile your program and download it

Work with the person next to you to test your program and follow these steps to complete your activity

  • On your block editor on the top click “Compile”

  • This will download your script to download folder
  • Copy your script and place into or drag and drop it on your micro:bit
  • Your micro:bit should start flashing. Do not touch it until its finish flashing
  • Once it’s complete then you can unplug it from your computer and plug the battery pack
  • And test your program with your pair by playing rock paper scissors
  • Hold the micro:bit in your palm and shake your hand as you would do in normal Rock Scissors and paper game

If you are having problem to download your script. Right click on the below link and use Save link as then save it in your folder.
microbit-rock-paper-scissors-game-code

Task 3 – Excellent, you’re ready to continue with the challenges!

Challenge 1

When the A button is pressed, increment the score by 1. You can select Game drawer then add change score by 1.

Click run to execute your code in the simulator

Task 4 – Print score on your micro:bit

Challenge 2

After incrementing the score, display the total number of wins you have.

Run and compile the code to see if it works as expected.

If you are having problem to download your script. Right click on the below link and use Save link as
microbit-rock-paper-scissors-game-code-final

Home learning – due in next lesson

You have successfully tracked and displayed the number of wins on the BBC micro:bit! However, what about losses? Use the Game drawer to change score by -1 when button B is pressed.

Run and compile the code to see if it works as expected.

You can also find this homework in your Show My Homework account.
Use the below links to help you with your task
Computational Thinking
About micro:bit