Hummingbird Bit: MakeCode Lessons

Lessons

Module 1: Setup

Steps 1 2 3 4 5 6 7 8
Steps 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Steps 1 2 3 4 5
Steps 1 2 3 4 5
Steps 1 2 3 4 5 6 7 8 9
Steps 1 2 3 4 5 6
Steps 1 2 3 4 5 6 7 8 9 10 11 12
Steps 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Step 1

This module will cover how to create a MakeCode program for the Hummingbird Bit and how to download it to the micro:bit.

Step 2

Insert a micro:bit into your Hummingbird Bit Controller, and connect it to the computer with the USB cord. The Hummingbird also needs a source of power, so connect it to the battery pack or AC power adapter.

Step 3

Use this button to open the MakeCode Environment. These lessons show the Chrome browser, but you can use any browser.

Step 4

The micro:bit simulation doesn’t work with Hummingbird, so minimize it to make more room for your programs.

Step 5

Your new MakeCode program for micro:bit automatically contains a few items that you will need for every program. Blocks inside on start will run when you download the code to the micro:bit or turn the micro:bit on. After that, blocks inside forever will run over and over as long as the micro:bit has power. If you are using the Hummingbird, the on start block must always contain the Start Hummingbird block.

Step 6

Rename your program. MakeCode will automatically save your project under this name.

Step 7

Set your browser to ask you where to download files. This will make it easier to load your programs to the micro:bit.

Step 8

To load a program onto the micro:bit, click the purple Download button. Select the micro:bit as the download location.

Step 1

In this module, you will learn to use the lights, which are also called light-emitting diodes, or LEDs. The Hummingbird kit contains single color LEDs and tri-color LEDs. Single color LEDs have two wires, while tri-color LEDs have four wires. The surface of the micro:bit contains 25 tiny LEDs that you can use to make pictures and patterns!

Step 2

In the Basic menu, there are two blocks that enable you to create simple pictures on the micro:bit. The show icon block allows you to select from a list of pictures.

Step 3

The pause block stops the program for a number of milliseconds.

Step 4

The show leds block lets you pick which LEDs should be on and which should be off.

Step 5

To run this program, you will first need to download it onto your micro:bit. Click the Download button. After a moment, your program will run.

Step 6

Teacher Note: The video shows one example, but students may create lots of different rabbits with the show leds block!

Step 7

Leave Start Hummingbird in the on start block, but delete the other three blocks.

Step 8

The Set LED block on the Hummingbird menu is used to control a single color LED. To use this block, first select the port to which the LED is attached (one to three). Then set the brightness of the LED from 0% to 100%.

Step 9

 

Step 10

To turn the LED off, set the brightness to 0%.

Step 11

Use two Hummingbird LED blocks and two pause blocks to blink the LED once when the micro:bit starts.

Step 12

Drag the Hummingbird LED and pause blocks into the forever block. The forever loop is a loop; a loop repeats actions within a program. Now your LED will blink over and over!

Step 13

 

Step 14

Remember that you need a second pause block. The video shows one solution, but you can use any two pictures!

Step 15

Add two Hummingbird Tri-LED blocks to your program to use the tri-color LED. In the Hummingbird Tri-LED block, select the port of the tri-color LED (1 or 2) and the amount of red, green, and blue light from 0 to 100.

Step 16

 

Step 17

 

Step 1

In this module, you will use the position servo. The position servo is a motor that moves to a particular angle. The Hummingbird position servo can move to any angle from 0° to 180°.

Step 2

Delete any extra blocks from your program so that you are blinking one single color LED.

Step 3

Add two Hummingbird Position Servo blocks so that the position servo moves back and forth as the LED blinks. In each position servo block, select the port of the servo (1-4) and the angle to which it should move (0° – 180°).

Step 4

 

Step 5

 

Step 1

The micro:bit has two buttons labelled ‘A’ and ‘B.’ You can write scripts that will run when one button is pressed, or when both are pressed together.

Step 2

Use the on button pressed block on the Input menu to make the LED blink and the position servo move when you press button A.

Step 3

Now right-click (control-click on Mac, Alt-Click on Chromebooks) to duplicate the on button pressed script. In the second script, select button B, LED port 2, and servo port 2. Now button B can control a second LED and servo!

Step 4

 

Step 5

 

Step 1

The light sensor measures the amount of light around it. You can use this sensor to make a robot that can detect when it is dark or bright.

Step 2

You can use the show number block from the Basic menu to print the value of the light sensor on the micro:bit LED array. Notice that the Hummingbird Light block has a different shape. This shape tells you that this block gives the program a number; this number is the amount of light in the room from 0 to 100.

Step 3

 

Step 4

You can use a sensor to enable a robot to make a decision. For example, suppose you want to turn on an LED if the light sensor detects that it is dark.

The if then else block is a decision block. The if then else block has three parts.

Step 5

At the top beside the if is a Boolean block, which is a block that can be either true or false. You can create a Boolean block using the comparison operators from the Logic menu.

Drag a Hummingbird Light block into a less than comparison.

Step 6

The Boolean block in our sample program checks whether the value of the light sensor is less than 20.

Step 7

If the light sensor is less than 20, the block inside the then section of the if then else is executed, and the LED turns on. If the Boolean block is false, the block inside the else section of the if then else is executed, and the LED turns off. The value that a Boolean block uses to make a decision is called the threshold. In the sample program, the threshold is 20. If the value of the light sensor is less than this threshold, the program decides that it is dark.

Step 8

 

Step 9

The Boolean block in the if then else is checked each time the program repeats the decision. However, the Boolean block is not checked during the statements inside the then or else parts of the block.

Step 1

The Hummingbird Rotation Servo block is used to control the rotation servo. To use this block, first select the port to which the rotation servo is attached (one to four). Then set the speed of the motor from -100% to 100%.

Step 2

This script repeatedly turns the rotation servo on for two seconds and then off for two seconds.

Step 5

You can use the pick random block from the Math menu to set the speed of the motor to a random value once each second. By default, the block generates a random number between 0 and 4, but you can change the 4 to any positive integer.

Step 1

In Module 5, you used the Hummingbird Light block to measure the amount of light in the room. You can also use this block to find the value of the Hummingbird dial, distance, or sound sensor. Select the sensor you want to use from the drop-down menu, and remember to choose the appropriate port.

Step 2

Like the light sensor, the value of the dial is between 0 and 100. This means that you can place it inside the Hummingbird LED block to set the brightness of the light.

Step 4

The dial is useful for controlling an LED because the range of the Hummingbird Dial block (0-100) is the same as the range of brightness for the LED. If you place the dial block inside the Hummingbird Position Servo block as shown, the position servo will only move from 0° to 100°.

Step 5

You can make the servo move from 0° to 180° using arithmetic blocks from the Math menu. These blocks enable you to add, subtract, multiply, and divide numbers.

Step 6

One way to use the Hummingbird Dial block to produce an angle between 0° and 180° would be to multiple it by 1.8. Unfortunately, it is not possible to use decimal numbers with micro:bit. If you try it, you will see an error.

Step 7

To avoid decimal numbers, first multiple the dial value by 18 and then divide by 10. Note that when you place one arithmetic block inside another, the operation in the innermost block will be performed first. Here, the dial block will be multiplied by 18, and then the result will be divided by 10. In math terms, each arithmetic block acts like a pair of parentheses; the expression in this script below is ((18*dial)/10).

Step 9

You can also use the micro:bit accelerometer to control LEDs and motors. You can measure the micro:bit’s acceleration using the acceleration block on the Input menu. The accelerometer can measure the tilt of the micro:bit in three directions, which are called x, y, and z. You can use the drop-down menu in the acceleration block to select one of these directions.

Step 10

The value of the acceleration block is always between 0 and 1024. To use it to control a Hummingbird output, you need to use the division operator to reduce this value to a range within 0 to 100. For example, this script will use the three directions of acceleration to control the three light elements of the tri-color LED.

Step 1

Start by programming the second micro:bit. Since it is not connected to a Hummingbird Bit, you do not need a Start Hummingbird block. Instead, the on start should contain a radio set group block. To send radio messages to one another, two (or more) micro:bits must be set to the same radio group. Here, the radio group number is 120.

Step 2

A micro:bit can send a message using the radio send string block or the radio send value block. Send the string “on” when button A is pressed and the string “off” when button B is pressed.

Step 3

Next, program the micro:bit connected to the Hummingbird Bit. This micro:bit should also be set to radio group 120. Since you are using two devices, it may be helpful to open a second MakeCode window with a second project.

Step 4

A second micro:bit can listen for the messages sent by the first one. If the first micro:bit is using radio send string, then the second should use the on radio received receivedString to listen for messages.

Step 5

When the Hummingbird receives a string, it can use an if then else to see which of the two possible messages it has received.

Step 6

Check whether the string that is received is equal to “on.” The receivedString block is on the Variables menu. However, you can’t replace the 0 with the string “on.”

Step 7

Use a block with quotation marks to tell MakeCode that you are using a string. This block can be found on the Text menu under Advanced.

Step 8

Turn the rotation servo on when the Hummingbird receives the string “on” and off otherwise.

Step 10

You can also send messages based on sensor values. For example, a single micro:bit can send “forward” when the micro:bit is tilted downwards (so the logo is down).

Step 11

When the Hummingbird Bit receives the “forward” message, it turns on two rotation servos in opposite directions. If the rotation servos are placed on either side of a small rover, they can be used to drive the robot forward.

Step 15

The micro:bit can send and receive numbers, as well as strings. You can use the radio send number block to send a single number. This code will send the x-value of the micro:bit accelerometer repeatedly via the radio.

Step 16

If the first micro:bit is using radio send number, then the Humminbird Bit should use the on radio received receivedNumber to listen for messages. This program uses the number received to control the speed of the rotation servo. The receivedNumber block is on the Variables menu.