how to program with the bbc micro:bit - wordpress.com · 7 how to upload to a bbc micro:bit – mac...

18
How to Program with the BBC micro:bit

Upload: hoangcong

Post on 03-Apr-2018

243 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

How to Program with the BBC micro:bit

Page 2: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

2

Contents

Website………………………………………………………………………………………....... 3

Using Microsoft Block Editor……………………………………………............ 4

Your First Program…………………………………………………………………......... 5

Compiling your Program…………………………………………………………………. 6

Uploading to your micro:bit using a MAC………………………………….. 7

Uploading to your micro:bit using a Windows Computer………… 8

Display Letters and Words…………………………………………………………… 9

Display an Image………………………………………………………………………........ 9

Changing Images……………………………………………………………………………… 10

Loops………………………………………………………………………………………………….. 11

Brightness………………………………………………………………………………………... 12

Variables…………………………………………………………………………………………… 13

Random Number Generator…………………………………………………………… 14

IF / ELSE………………………………………………………………………………………….. 15

Display a Random Image using IF………………………………………………… 16

Multiple IFs………………………………………………………………………………………. 17

Page 3: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

3

www.microbit.org

Click here

You have a choice

of programming

languages

We used

Microsoft Block

Editor

Page 4: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

4

Microsoft Block Editor

How to start a program

Programming

Commands

Programming

Area

Micro:bit simulator

to see your

programs working

Clicking on one of the Coloured

Programming Areas will display

all the options for that Block of

Commands.

Simply click and drag the block

you want to use into the

Programming Area

Page 5: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

5

Your First Program

This simple program creates the image of a Dog using the led’s (Light Emitting

Diodes).

Step 1

Give your program a name – “Dog” in this case.

Step 2

Drag the Purple Input block into the programming area.

Step 3

Drag blue/grey Basic block into the programming area. Drag this block inside

the purple block. Make sure it clicks into place.

Step 4

Press the RUN button at the top of the screen. This part is often forgotten,

especially after making a change to a program.

Step 5

Click the A Button on the simulator. You should see your program running.

Page 6: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

6

How to compile your program

If you want to put your program onto a physical micro:bit, you will need to

compile it first.

Click on the COMPILE button at the top of the screen

The compile button will spin and you will see the following page for a few

seconds

The program will have been saved into your area as a “.hex” file. Giving your

program a name BEFORE you compiled it will make it easier to find

Page 7: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

7

How to upload to a BBC micro:bit – MAC

The program will be in your “Downloads” folder

Plug your micro:bit into your MAC. It will show on your screen as a new drive

Reduce your Downloads window so you can see the micro:bit drive and simply

drag the program into the micro:bit

Your program is now on your micro:bit and ready to run

Page 8: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

8

How to upload to a BBC micro:bit – WINDOWS

You choose where to save the file

I saved it in a new folder called Microbit Files

Plug the micro:bit into your computer. It shows as a new device

I can then simply drag it from the Microbit Files folder into the

Microbit that shows up on the left of my screen

Your program is now on your micro:bit and ready to run

Page 9: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

9

Skill Builders

Display a message when button A is pressed

The message is called a “string” which means it can be letters, words, numbers

or a mixture of any of them.

The message will scroll sideways across the micro:bit

Display an Image when Button A is pressed

Page 10: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

10

Display swaps between 2 images with a short pause when Button A is

pressed

You can add extra images

Page 11: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

11

Display swaps between 2 images with a short pause when Button A is

pressed. This will be repeated 5 times using the “repeat” block.

This is called a LOOP

Page 12: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

12

Changing the Brightness of the LEDs

You can change the brightness of the LED’s by using the SET

BRIGHTNESS block

Page 13: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

13

Variables

Sometimes you will need to use a VARIABLE. This is a value that can

CHANGE. You will need to give a variable a NAME.

Notice that once you have created a variable and given it a name, it

appears in the VARIABLES set of blocks for you to choose.

Page 14: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

14

Random Number Generator

This Block creates a Random Number between 0 and a number of your

choosing. REMEMBER that computers see the number 0 as the first

number in a list so the block above would pick 1 of 5 choices.

Either 0, 1, 2, 3 or 4.

This works well with a VARIABLE.

These blocks click together to create a VARIABLE called RANDOM

NUMBER which will produce a random number between 0 and 4.

Page 15: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

15

IF / ELSE

This block is really useful, but you need to build it to use it. It is used

to choose between two different outcomes.

Step 1

Select the IF block

Step 2

Click on the Blue Square to see your

options

Step 3

Choose the ELSE block and click it

inside the IF block

Step 4

Click on the Blue Square again.

This is your new block

Page 16: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

16

How to use the IF block with a VARIABLE and the RANDOM

NUMBER GENERATOR blocks

Every time the A Button is pressed, the number 0 or 1 will be chosen

randomly. I have called this variable “Heart” which describes the

image. Image 1 will be displayed if the Random Number is 0 and

Image 2 if the Random Number is 1. You DON’T have to actually use

the number 1, as it falls into the ELSE part of the LOOP.

i.e.

If the random number is 0, show the FIRST Image, ELSE, show the

SECOND image.

Random Number = 0

Random Number = 1

Page 17: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

17

Lots of Ifs

If you want to have MORE than 2 results, you need to create an IF

statement that also includes an ELSE IF block

You can add as many ELSE IF blocks as you like. It is GOOD

PRACTICE to end with an ELSE. This means there will ALWAYS be an

output as ELSE covers every other option.

Page 18: How to Program with the BBC micro:bit - WordPress.com · 7 How to upload to a BBC micro:bit – MAC The program will be in your “Downloads” folder Plug your micro:bit into your

18

To allow 3 possible outcomes, the code looks like this