Single Color LED
Setup
This module will cover how to create a MakeCode program for the Hummingbird Bit and how to download the program to the micro:bit.
Please note that there is no sound in these videos.
Insert a micro:bit into your Hummingbird Bit Controller (you might need to push a little harder than you think!). The Hummingbird also needs a source of power, so connect it to the battery pack or AC power adapter. Connect your micro:bit to the computer with the USB cord. If you are using rechargeable batteries, check out this support article before using.
Note: MakeCode Bluetooth capability does not work reliably with our products. See our support article for more details.
Use this button to open the MakeCode Environment. These lessons show the Chrome browser. We recommend Chrome, but Makecode will work in most browsers. You can also go to makecode.microbit.org, click “Advanced” in the blocks menu, then click “+Extensions”, and search for the Hummingbird extension.
Minimize the micro:bit simulation (the image on the left) to make more room for your programs. This simulator does not work with the Hummingbird Bit.
Give your program a useful name. MakeCode will automatically save your project under this name.
To get a sense of what it is like to load a program onto the micro:bit, click the purple Download button. Select the micro:bit as the download location. By default, MakeCode will send a smiley face to your micro:bit LED screen.
In addition to the programming tutorials on this page, we have a lot of other resources to help you work with with your Hummingbird Kit.
- Our coding cards provide printable programming help for your students.
- Our blocks document is a handy reference guide that lists all the Hummingbird blocks in MakeCode.
- Our Build pages offer tutorials and inspiration for building your own robots and mechanisms.
- Our free Professional Development course ties everything together in an online course you can watch at your own pace.
Downloading a File
Instead of downloading a program’s .hex file to the Finch, you can download it to your computer or Chromebook. After clicking Download, select the location where you want to save the .hex file and click Save. You can then email the file, store it on a USB drive, or treat it as you would any other file.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123043.355-768x407.png))Loading a File
To load a file that you have saved in a .hex file, click on the Home button in MakeCode. From the home screen, click on the Import button.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123206.999-768x290.png))Click on Import File.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123211.944-768x349.png))Click on Choose File and navigate to the file you saved. Select it and then click Go ahead! Your file will open in MakeCode.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123218.501-768x360.png))Sharing a File
To share a file, click on the Share button in MakeCode
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123411.203-768x318.png))Click Publish Project.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123419.366-768x339.png))MakeCode will show you a link that you can share with others. Alternatively, you can also click Embed to see code to embed your project in a website.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/pasted-image-0-2020-07-10T123426.428-768x277.png))Single Color LED
This module will show you how to use a single color LED with the Hummingbird Bit. A single color LED is a small light with two wires. The colored wire shows the color of the LED. The Hummingbird kit comes with red, green, and yellow LEDs.
Please note that there is no sound in these videos.
Use the terminal tool to plug an LED into LEDS port 1 on the Bit. The colored wire should be connected to ‘+’ and the black to ‘-.’
The Hummingbird LED block is used to control a single color LED. To use this block, set the port of the LED to 1, 2 or 3 (MakeCode defaults to port 1), and set the brightness of the LED from 0% to 100%.
The forever loop runs the Hummingbird LED block over and over. Since it sets the brightness to 100% each time, the light stays on at full brightness.
Reflect: What do you think would happen if you set the LED to 50% instead of 100%?
Add a pause block, a second Hummingbird LED block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.
Each time through the loop, the program turns the LED on, pauses, turns the LED off, and pauses again. The forever loop repeats this process over and over.
Reflect: What do you think would happen if the second pause block was not there?
Tri-Color LED
This module will show you how to use a tri-color LED with the Hummingbird Bit. A tri-color LED is a small light with four wires. The tri-color LED actually has three tiny lights inside it. One is red, one is green, and one is blue. You can combine different amounts of red, green, and blue light to make different colors.
Please note that there is no sound in these videos.
Use the terminal tool to plug a tri-color LED into TRI-COLOR port 1 on the Bit. The red wire connects to ‘R,” the green to ‘G,’, the blue to ‘B,’ and the black to ‘-.’
The Hummingbird Tri-LED block is used to control a tri-color LED. To use this block, set the port of the LED to 1 or 2 (MakeCode defaults to port 1), and the amount of red, green, and blue from 0% to 100%.
The forever loop runs the Hummingbird Tri-LED block over and over. Since red is set to 100% each time and green and blue to 0%, the light is red.
Reflect: What do you think would happen if you set both red and blue to 100?
Add a pause block, a second Hummingbird Tri-LED block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.
Each time through the loop, the program turns the LED red, pauses, turns the LED blue, and pauses again. The forever loop repeats this process over and over.
Reflect: How can you use a tri-color LED in a robot?
LED Screen
In this module, you will learn to display icons and patterns on the micro:bit screen.
Please note that there is no sound in these videos.
When the space bar is pressed, the micro:bit Display is set to the image you created. Since the display was never programmed to turn off, the image remains on the screen.
Reflect: How would you change this code to display a different image?
Add a pause block, a second show icon block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.
Each time through the loop, the program shows the first expression, pauses, shows the second expression and pauses again. The forever loop repeats this process over and over.
Reflect: How would you change the code to show 3 different expressions on the micro:bit?
Position Servo
In this module, you will learn to 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°.
Hummingbird Base Kit users have an FS90 Micro Servo that works the same as the servo in these modules.
Please note that there is no sound in these videos.
Plug in the position servo to SERVOS port 1 on the Bit. Make sure the black wire is aligned to ‘-,’ the red wire to ‘+,’ and the white wire to ‘S.’
The Hummingbird Position Servo block is used to control the position servo. To use this block, set the port of the servo to 1, 2, 3 or 4 (MakeCode defaults to port 1) and the angle from 0° to 180°.
The forever loop runs the Hummingbird Position Servo block over and over, setting it to 90° each time.
Reflect: Why do you think the position servo moves once, then stops at 90°? Would the servo move if it was already at 90° before you start the program?
Add a pause block, a second Hummingbird Position Servo block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.
Each time through the loop, the program moves the servo to 90°, pauses, moves the servo to 180°, and pauses again. The forever loop repeats this process over and over.
Reflect: How would the movement of the servo change if the pause blocks were set to 300 ms instead of 1000 ms?
Rotation Servo
In this module, you will learn to use the rotation servo. The rotation servo is a motor that can rotate at different speeds.
The rotation servo is not included in the Hummingbird Bit Base Kit.
Please note that there is no sound in these videos.
Plug in the rotation servo to SERVOS port 1 on the Bit. Make sure the black wire is aligned to ‘-,’ the red wire to ‘+,’ and the white wire to ‘S.’
The Hummingbird Rotation Servo block is used to control the rotation servo. To use this block, set the port of the servo to 1, 2, 3, or 4 (MakeCode defaults to port 1) and the speed from -100% to 100%.
The forever loop runs the Hummingbird Rotation Servo block over and over, setting it to 100% each time.
Reflect: What would happen if you set the speed of the Hummingbird Rotation Servo to -100% instead?
Add a pause block, a second Hummingbird Rotation Servo block, and a second pause block to the forever loop. The pause block stops the program for a number of milliseconds.
Each time through the loop, the program turns the motor on, pauses, turns the motor off, and pauses again. The forever loop repeats this process over and over.
Reflect: What do you think would happen if you changed the speed in the second Hummingbird Rotation Servo block to 40 instead of 0?
Buzzer
This module will show you how to program the buzzer output on the Hummingbird Bit. The buzzer can be used to create different musical tones that come directly from the Hummingbird controller board. The range of the buzzer is Low C to High B, or 131 to 988 Hertz (Hz).
Please note that there is no sound in these videos.
Drag out 3 play tone Middle C for 1 beat blocks from the Music folder and snap them into the Forever loop. Use the drop down menu on each block to select different notes. The range of the buzzer is Low C to High B, or 131 to 988 Hz.
Tip: Your browser will preview the tones through your computer’s speakers. Once you download the code, the sound will come through the board.
The notes you’ve programmed will play for 1 beat, one right after another. In music, the “beat” represents how long a note will play. We’ll learn to speed this up and slow this down next.
Reflect: How could you make the notes play for longer?
To make the notes play faster or slower, use the set tempo to (bpm) block from the Music folder. Snap the set tempo to (bpm) block into the top of the forever loop.
The “tempo” is the speed of a song. It is measured in beats per minute (bpm). MakeCode defaults to 120 bpm. Change the tempo by clicking the white oval and use your keyboard to set a new tempo.
Using a little bit of math, we can find that a song with 120 bpm has beats lasting half a second (120 bpm / 60 seconds in a minute = 2 beats in each second). Use the drop down menu to change the bpm and see how that affects the speed of the notes.
Reflect: What would you set the bpm to make a song where each beat = 1 second?
Drag out 3 rest(ms) blocks from the Music folder. Place one rest(ms) block after each play tone blocks. These blocks will cause there to be a silence, called a “rest.” Use the drop down menu to adjust the length of each rest.
The notes you’ve programmed will now play with silences or “rests” in between them. You can now program your Hummingbird to play any song at any tempo!
Light Sensor
This module will show you how to use a light sensor as an input with the Hummingbird Bit. A light sensor is a component that collects data based on how much light surrounds the sensor. The range of the light sensor is 0 to 100.
This module assumes that you have already completed the single color LED module.
Please note that there is no sound in these videos.
Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’
To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.
The Hummingbird Sensor block is near the bottom of the Hummingbird folder in MakeCode. Use the drop-down menu to select “Light.”
Interact with the light sensor and watch the number on the micro:bit LED screen change.
Reflect: How can you make the value of the sensor higher or lower?
The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.
Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?
Your light sensor value can be used to make decisions. To turn on an LED when the value of the sensor is low, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.
This program compares the value of the light sensor to 10. If the sensor value is less than 10, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is greater than 10, the program runs the block inside the else section, turning the LED off.
Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.
Dial Sensor
This module will show you how to use a dial sensor as an input with the Hummingbird Bit. A dial sensor is a component that collects data based on how much you rotate the knob. The range of the dial sensor is 0 to 100.
This module assumes that you have already completed the single color LED module.
Please note that there is no sound in these videos.
Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’
To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.
The Hummingbird Sensor block is near the bottom of the Hummingbird folder in MakeCode. Use the drop-down menu to select “Dial.”
Interact with the dial sensor and watch the number on the micro:bit LED screen change.
Reflect: How can you make the value of the sensor higher or lower?
The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.
Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?
Your dial sensor value can be used to make decisions. To turn on an LED when the value of the sensor is high, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.
This program compares the value of the dial sensor to 50. If the sensor value is greater than 50, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is less than 50, the program runs the block inside the else section, turning the LED off.
Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.
Distance Sensor
This module will show you how to use a distance sensor as an input with the Hummingbird Bit. A distance sensor is a component that collects data based on how close or far you are to the sensor. The range of the distance sensor is 1 to 260 cm.
The distance sensor is not included in the Hummingbird Bit Base Kit.
This module assumes that you have already completed the single color LED module.
Please note that there is no sound in these videos.
Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’
To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.
The Hummingbird Sensor block is near the bottom of the Hummingbird folder in MakeCode. Use the drop-down menu to select “Distance.”
Interact with the distance sensor and watch the number on the micro:bit LED screen change.
Reflect: How can you make the value of the sensor higher or lower?
The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.
Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?
Your distance sensor value can be used to make decisions. To turn on an LED when the value of the sensor is low, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.
This program compares the value of the distance sensor to 15. If the sensor value is less than 15, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is greater than 15, the program runs the block inside the else section, turning the LED off.
Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.
Sound Sensor
This module will show you how to use a sound sensor as an input with the Hummingbird Bit. A sound sensor is a component that collects data based on how much sound surrounds the sensor. The range of the sound sensor is 0 to 100.
The sound sensor is not included in the Hummingbird Bit Base Kit.
This module assumes that you have already completed the single color LED module.
Please note that there is no sound in these videos.
Plug a sensor into your board. Any Hummingbird sensor can be connected to any of the three ports labelled “SENSORS” on the Bit. The yellow wire connects to ‘S,’ the red to ‘+,’ and the black to ‘-.’
To see the value of the sensor on the micro:bit LED screen, place the Hummingbird Sensor block inside a show number block.
The Hummingbird Sensor block is near the bottom of the Hummingbird folder
in MakeCode. Use the drop-down menu to select “Sound.”
Interact with the sound sensor and watch the number on the micro:bit LED screen change.
Reflect: How can you make the value of the sensor higher or lower?
The Hummingbird Sensor block measures the value of the light sensor and sets the LED brightness to that value.
Reflect: In this program, the micro:bit runs the Hummingbird LED block about 40 times per second. What do you think would happen if you added a pause block to the forever loop?
Your sound sensor value can be used to make decisions. To turn on an LED when the value of the sensor is high, use an if else block from the Logic folder. This block requires a comparison block, which is also in the Logic folder.
This program compares the value of the sound sensor to 70. If the sensor value is greater than 70, the program runs the block inside the if section of the if else, and the LED turns on. When the sensor value is less than 70, the program runs the block inside the else section, turning the LED off.
Can you make an LED turn on and off with a different sensor? Disconnect the sensor you’ve been using and connect a new sensor. Use the drop-down menu in the Hummingbird Sensor block to make the block match your new sensor.
Buttons
This module will show you how to program the A and B buttons on the micro:bit to control the single color LED output of the Hummingbird Bit. The micro:bit’s A and B buttons can be used as inputs. Pressing them can be an “event” to trigger other actions.
This module assumes that you have already completed the single color LED module.
Please note that there is no sound in these videos.
Plug in a single color LED. The A and B buttons are located on the face of the micro:bit. They can be pressed one at a time or together.
Remove the forever loop from your screen. Drag out the on button A pressed block from the Input folder. Drag a Hummingbird LED block from the Hummingbird into the loop. Set the Hummingbird LED to 100%. Download the code.
The A button being pressed causes the Hummingbird LED to turn on.
Reflect: How could you use the A button to turn a tri-color LED red?
Drag out another on button A pressed block from the Input folder. Use the drop down menu to change the second code to on button B pressed. Program the Hummingbird LED to turn off when the B button is pressed.
Accelerometer
This module will show you how to use the accelerometer as an input to control a Hummingbird tri-color LED. The range of the x, y, and z variables on the accelerometer is -1024 to 1024 mg.
This module assumes that you have already completed the tri-color LED module.
Please note that there is no sound in these videos.
Plug in the tri-color LED. You do not need to attach the accelerometer. The accelerometer is built into the micro:bit.
Remove the forever loop from your screen. Drag out the on shake block from the Input folder. Drag out 2 Hummingbird Tri-LED blocks from the Hummingbird folder and 1 pause (ms) block from the Basic folder. Write a program to turn the tri-color LED on and off inside of the on shake block.
When you shake the Hummingbird controller board, your tri-color LED will turn red for 1 second and then turn off.
Reflect: How could you make the tri-color LED blink red and blue 3 times when the micro:bit is shaken, then turn off? (Hint: Look in the Loops folder!)
You can also tilt your Hummingbird Bit in different directions to change the colors of the tri-color LED.
First, delete the pause and second Hummingbird Tri-LED blocks. Select the drop down menu in the on shake block, and change it to read “logo up.” Duplicate this whole event. Then, use the drop down menu to select “logo down” in the second on shake block. Change the tri-color LED to green on the second Hummingbird Tri-LED block.
When you tilt the Hummingbird Bit controller forward and back, the tri-color LED will change color from red to green.
Reflect: How could you make this code control a position servo to go from 0 to 180 degrees?
While we’ve been using the accelerometer as an event up to this point, you can also use the accelerometer’s value to slowly alter a component by nesting it, which you can also do with sensors. This action requires us to use some math.
First, delete your 2 on logo up and on logo down event blocks. Drag out a forever loop from the Basic folder. Drag a Hummingbird Tri-LED block into the forever loop. Drag a division block from the Math folder. Nest this block into the white oval next to “Red” in the Hummingbird Tri-LED block.
Nest an acceleration (mg) x block from the Basic folder into the first space in the division block. This accelerometer can measure front to back movement (called x), side to side movement (called y), and up and down movement (called z). Use your keyboard to type the number 10 into the second space of the division block.
Why do you need a math block here? The range of the x, y, and z values on the accelerometer is -1024 to 1024 mg. In order for this sensor to effectively control the tri-color LED, which has a range of 0-100, we need to divide the value of the accelerometer block by about 10.
Reflect: How could you make the y variable of the accelerometer control the brightness of the blue of the tri-color LED at the same time?
Write a program that:
– Makes the x variable of the accelerometer control the brightness of the red of the tri-color LED.
– Makes the y variable of the accelerometer control the brightness of the blue of the tri-color LED.
– Makes the z variable of the accelerometer control the brightness of the green of the tri-color LED.
Compass
This module will show you how to use the compass as an input to control the movement of a Hummingbird position servo. The range of the compass is 0° to 359°.
This module assumes that you have already completed the position servo module.
Please note that there is no sound in these videos.
Drag the show number block from the Basic folder into a forever loop. Drag the compass heading block from the Input folder into the show number block.
The compass needs to be calibrated before it can be used. Follow the steps displayed on the micro:bit’s LED array to calibrate the compass. The micro:bit asks you to “TILT TO FILL SCREEN.” Tilt the micro:bit so that all the LEDs on the LED display screen are lit. This step will need to be repeated each time you download.
The micro:bit’s LED screen is now displaying the input value from the compass. The compass measures its heading in degrees, from 0-360. North is 0.
Reflect: What number represents South?
Drag the compass heading block out of the show number block and delete the show number block. Drag out a Hummingbird Position Servo block from the Hummingbird folder and nest the compass heading block inside of it.
The position servo will now rotate to match the compass heading. Although the range of the compass is 0°-359°, the position servo will stop at 180 degrees, because the range of the position servo is 0°-180°.
Reflect: How could you use the compass to control the brightness of a single color LED?
The compass value can also be used to make decisions. We will now set your position servo to either 0 or 180 degrees based on the compass value.
First, drag the compass heading and Hummingbird Position Servo blocks apart and outside of the forever loop. Drag an if else block from the Logic folder into the forever loop. Nest a less than block from the Logic folder into the hexagon space of the if else block.
Nest the compass heading block into the first space of the less than block, and type “180” degrees into the second space. Drag the Hummingbird Position Servo block into the first open space of the if else block and set it to “0.” Drag another Hummingbird Position Servo block into the second open space of the if else block and set it to “180.”
This program compares the value of the compass to 180. If the compass value is less than 180 (indicating west), the position servo is set to 0 degrees. When the compass value is greater than 180 (indicating east), the position servo is set to 180 degrees.
Reflect: How could you use a similar code to turn a tri-color LED red and blue based on the value of the compass?
Radio
This module will show you how to use the radio feature to transmit data from one Hummingbird controller to another, “controlling” one device with another. For this module, you will need 2 Hummingbird Bit boards*, 1 tri-color LED, and 1 dial sensor.
This module assumes that you have already completed the tri-color LED, buttons, and sensor modules.
*In steps 2-8, you will be using a micro:bit by itself without a Hummingbird controller board. To power this micro:bit, you can either use a AAA battery pack or the USB cord included in your kit.
Please note that there is no sound in these videos.
We will begin by programming the “transmitting” Hummingbird (which we will call HB1) to send a message when the A button is pressed. Eventually, pressing the A button on HB1 will turn the tri-color LED on HB2 red.
On HB1:
First, remove the forever loop from your screen. Next, set the radio group by dragging out the radio set group block from the Radio folder into the On Start loop. Set the radio group to a number between 1-255. Drag out the on button A pressed block from the Input folder. Drag the radio send string block from the Radio folder into the on button A pressed loop. Give the string a message like “red.” (Capitalization will matter, so carefully note the exact string you are sending).
We will now program the “receiving” Hummingbird (HB2) to use a received message to turn the HB2 tri-color LED red.
On HB2:
First, remove the forever loop from your screen. Next, drag out the radio set group block from the Radio folder into the on start loop. Set the radio group to the same number as your HB1. Drag out the on radio received – receivedString block from the Radio folder. Drag a Hummingbird Tri-LED block from the Hummingbird folder into the on radio received – receivedString block. Set Red to 100%.
When the A button is pressed on HB1, the tri-color LED on HB2 turns red.
Reflect: Could you write a similar script to make a message or picture appear on the LED screen of HB2 when you press the A button on HB1?
Now we want to program our linked Hummingbirds so that pressing the A and B buttons on HB1 will turn the tri-color LED on HB2 red and blue.
First, duplicate the on button A pressed loop and set it to on button B pressed. Give this string a different message like “blue.” (Capitalization will matter, so make note of the string you are sending).
We now need a way for HB2 to differentiate between strings. Based on the string it receives, HB2 will either turn the tri-color LED red or blue.
On HB2:
First, remove the Hummingbird Tri-LED block from the on radio received loop and set it to the side. Drag an if then statement from the Logic folder into the on radio received block. Nest a 0 = 0 block from the Logic folder into the hexagon space of the logic blocks. Nest the receivedString block from the Variables folder into the first space in the 0 = 0 block.
Click “Advanced” on the bottom of the folders section to reveal the Text folder. Nest a ” _ “ block into the second space of the 0 = 0 block. Type “red” into that space, exactly matching the string HB1 sent. Drag a Hummingbird Tri-LED block from the Hummingbird folder into the on radio received – receivedString block. Set Red to 100%. Duplicate the if then block and set the text to “blue” and the tri-color LED to 100% blue.
When the A button is pressed on HB1, the tri-color LED on HB2 turns red. When B button is pressed on HB1, the tri-color LED on HB2 turns blue.
Reflect: How could you do something similar with a position servo, setting it to either 0 or 180 degrees based on which button is pressed?
Now we’re going to program a dial sensor on HB1 to control the tri-color LED on HB2.
On HB1:
First, drag the radio send string “red” and radio send string “blue” blocks to the side and save them for later. Delete the on button A pressed and on button B pressed blocks. Drag out a forever loop from the Basic folder. Drag an if then else statement from the Logic folder into the forever loop.
Nest a less than block from the Logic folder into the hexagon space of the if then else block. Drag the Hummingbird Light block from the Hummingbird folder into the first space of the less than block. Use the drop down menu to select “Dial.” Type “50” into the second space of the less than block. Drag the radio send string “red” block into the first space, and the radio send string “blue” block into the second space of the if then else statement.
We actually don’t need to change anything in our code for HB2! It will still be receiving the same strings, “red” or “blue,” but now the dial sensor will be triggering different strings instead of the A and B buttons.
Now, when you turn the HB1 dial sensor above 50%, the HB2 tri-color LED turns blue. When you turn the HB1 dial sensor less than 50%, the HB2 tri-color LED turns red.
Reflect: Could you recreate this same function with a different sensor?
Up to this point, we have been sending strings of text as messages. Now we will be sending number values as messages between HB1 and HB2. We will use the dial sensor on HB1 to control the brightness of the tri-color LED on HB2 in real time.
On HB1:
First, delete everything inside the forever loop. Drag out a radio send number block from the Radio folder. Nest the Hummingbird Dial sensor block into the radio send number block.
We need to reset the HB2 to look for its radio signal in numbers rather than strings of text.
On HB2:
Delete the on radio received – receivedString loop. Drag out an on radio received – receivedNumber block from the Radio folder. Drag out a Hummingbird Tri-LED block into the on radio received – receivedNumber loop. Nest a red receivedNumber block from the Variables folder into the tri-color LED red space.
As you turn the dial sensor on HB1, the brightness of the tri-color LED on HB2 will increase and decrease in real time.
Reflect: How could you make the dial sensor also control the brightness of the blue light in the tri-color LED?
Combining skills and components like accelerometer, compass, and motors can make for some great animatronic and puppeteering projects. What sort of animatronic puppet could you make, controlled by radio?
Temperature and V2 Sensors
This module will show you how to use three additional sensors: the temperature sensor, the micro:bit V2 touch sensor, and the micro:bit V2 sound sensor. The temperature sensor is present on all micro:bits, but the other two sensors can only be used if your Hummingbird contains a micro:bit V2.
The Temperature Sensor
Your Hummingbird can detect temperature using a sensor in the micro:bit. The micro:bit temperature sensor measures the temperature of the air in degrees Celsius. The value of the temperature sensor is measured with the temperature (°C) block on the Input menu.
For example, you can display an “H” on the micro:bit when the temperature is warmer than 20 degrees, and a “C” otherwise.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other1-768x730.png))CHALLENGE
Make a tri-color LED turn blue when the Hummingbird detects that it is cold and red otherwise.
Click Here to see example code.
The Touch Sensor
If your Hummingbird contains a micro:bit V2, the gold micro:bit logo is also a touch button. The logo is pressed block at the bottom of the Input menu returns true if you are touching it and false if you are not.
For example, you can make a tri-LED turn green when you are touching the button and red otherwise.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other3.png))The Input menu also contains the on logo pressed block. You can use this block to start a script when you touch and release the logo touch button, or you can use the drop-down menu to select other touch options. For example, you can press the logo to turn on the rotation servo.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other4-768x263.png))Note that these blocks can only be used with micro:bit V2. If you try to use them with micro:bit V1, you will see an unhappy face on the micro:bit LED display.
CHALLENGE
Write a program that moves the position servo to 0° when you press button A, 90° when you press button B, and 180° when you touch the logo.
Click Here to see example code.
The micro:bit V2 Sound Sensor
The micro:bit V2 also contains a sound sensor, which can detect a noise like a clap. This is similar to the sound sensor that comes with the Hummingbird Premium kit, but it is contained in the micro:bit rather than a separate sensor.
The value of the sound sensor can be measured with the sound level block at the bottom of the Input menu. The range of the micro:bit sound sensor is 0-255. For example, you can turn the rotation servo off when the micro:bit detects a noise and on otherwise.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other6-768x545.png))The Input menu also contains the on loud sound block. You can use this block to start a script when the micro:bit V2 detects a loud sound, or you can use the drop-down menu to select other sound options. For example, you can use this block to turn on an LED when you clap.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/other7.png))Note that these blocks can only be used with micro:bit V2. If you try to use them with micro:bit V1, you will see an unhappy face on the micro:bit LED display.
CHALLENGE
Make the Hummingbird play a note when you clap your hands.
Click Here to see example code.
Variables
What is a variable? In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Using variables with the Hummingbird Robotics Kit will help you create robots with more advanced functions.
Before you begin this module, make sure that you have completed the single color LED module, the position servo module, the buttons module, and at least one of the sensor modules.
You can name a variable anything you want, but it makes most sense to give it a name that matches its function. In this module, we are creating a variable that counts up and down when the A and B buttons are pressed, so a good name for this variable is “count.”
Nesting a variable into an output block is one way to use a variable. You can also use a variable to control robot expressions. If the variable equals 1, your robot can perform one set of actions. If your variable equals 2, your robot can perform a different set of actions.
Try building a robot using the variable to control different expressions. You can build any type of robot you want, but we recommend building the Tiny Drummer.
Creating a variable that counts on its own will require a good understanding of how loops work and of how pause blocks work. Create a variable that counts upwards on its own, then associate that counting variable with an LED. How does the LED react?
Programming a position servo to move slowly is very similar to programming an LED to fade in and out. Nest the counting variable block inside of a position servo block instead of an LED block.
To manually control the speed of that position servo with the A and B buttons we will need a new variable. Create a second variable and call it “time.”
If the wait time between servo positions is too big or too small, the servo can become difficult to work with. Set some parameters for your time variable. There are many ways to set variable parameters.
Try to build a robot that uses 2 slow moving servos. You can build anything you want, but we recommend the Little Bot.
Rover: Driving and Avoiding Obstacles
In this module, you will program a mobile robot to move and avoid obstacles. You will need a rover for this module, so go ahead and build one with this tutorial. We kept our rover pretty simple, but feel free to make yours a parade float, a bananamobile, or whatever you can dream up!
Note: The rover modules assume that you have already completed the modules in the Inputs and Outputs sections.
Moving Forward and Back
The two rotation servos on the rover point in opposite directions.
This means that to move the rover forward, the two servos must move in opposite directions.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image4.png))To move the rover forward, set the speed of rotation servo 1 to 100% and the speed of rotation servo 2 to -100%.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image4-1-768x477.png))CHALLENGE
Try out this code. Experiment with different wheel speeds to see how you can move the rover in different ways. How can you move backward?
Click Here to see example code.
Turning
When the speeds of the rotation servos are equal, the robot turns in place.
Notice that this code turns the rotation servos off at the end of the program. Otherwise, they will remain on when the script ends, and the rover will keep spinning.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image15-1-768x937.png))CHALLENGE
Try out this code. How can you change how far the robot turns?
Click Here to see example code.
Avoiding Obstacles
You can use the distance sensor to help your robot avoid obstacles. This program will stop the rover when it sees an obstacle less than 20 cm away. Otherwise, the rover will move forward.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image28-1-768x496.png))CHALLENGE
Modify your program to make the rover back up and turn left when it sees an obstacle. Now your rover can wander around the room!
Click Here to see example code.
Adding Extras
The rover also has two tri-color LEDs for headlights and a servo that controls the steering wheel. You can incorporate these components into your program as well.
CHALLENGE
Make the headlights turn red when the rover is moving away from an obstacle and green when the rover is moving forward. Make your driver steer by turning the steering wheel to the left as the robot turns left and back to the center when it is moving forward or back.
Click Here to see example code.
Rover: Randomness
In this module, you will learn to generate random numbers and use them to create interesting and sometimes unexpected behaviors for your rover. For example, you can use random numbers to make the rover move randomly with random colors for the headlights.
Generating Random Numbers
The pick random block is on the Math menu in MakeCode. This block randomly chooses a number between the two limits given. For example, this block generates a number between 0 and 10.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image20-1.png))You can use the pick random block anywhere that you would use a number in your program. For example, this program sets the speed of each rover wheel to a random number every two seconds. This program will make your rover wander randomly about the room!
Notice that each wheel gets a different random number, so the Finch will mostly turn but sometimes move straight. The random number for rotation servo 2 is multiplied by -1 to make this number negative.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image1-1-768x268.png))CHALLENGE
Use the pick random block to set the rover headlights to different random colors as the Finch moves randomly around the room.
Click Here to see example code.
Randomness with Variables
If you want to set both headlights to the same random color, you can add a variable to your program. Create a variable called red. If you need more information about how to make and use a variable, refer to the Variables module.
Set your variable equal to a random number between 0 and 100. Then set the amount of red for the tri-color LEDs to red.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image27-1.png))CHALLENGE
Create two variables, green and blue. Set each of these variables to a random number, and then use these variables to set the amount of green and blue light for both tri-color LEDs. When you are done, your program should set both tri-color LEDs to the same random color every second.
Click Here to see example code.
Rover: Radio Control
The Radio module covers how to send numbers and strings from one micro:bit to another. You can also send both a number and a string at the same time. This enables you to send labeled values from one micro:bit to another. This module will show you how to use this functionality to drive the rover using the accelerometer in a second micro:bit. When you tilt the second micro:bit, the rover will move and turn.
You will need an extra micro:bit for this module.
The Acceleration Block
Start by programming the micro:bit that you will use as the remote control. We will call this the sending micro:bit.
The micro:bit accelerometer measures any force that causes acceleration in the x-, y-, or z-direction. Because the micro:bit is usually moving pretty slowly, the accelerometer mostly measures the acceleration due to gravity. When the micro:bit is sitting on a level surface, the acceleration due to gravity points down perpendicular to the surface of the micro:bit, along the negative z-axis. If you instead position the micro:bit so that button B is toward the ground, the acceleration due to gravity points along the positive x -axis. The acceleration block on the Input menu enables you to measure these differences.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image26-1.png))To use the acceleration block, select the axis (x, y, or z) in the block. The block will report the acceleration in that direction in milligravities. Each acceleration value is roughly between -1000 and 1000. As an example, this code varies the icon shown on the micro:bit based on whether or not the x-value of the accelerometer is greater than 500 mg.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image23-1-768x505.png))CHALLENGE
Modify the program above so that the micro:bit shows a third icon when the y-value of the acceleration is more than 500 mg.
Click Here to see example code.
Sending Labeled Values with Radio
To control the rover, we need to send the x– and y-values of the acceleration from the sending micro:bit to the rover. To send a number with a label, use the radio send value block from the Radio menu. For example, the code below will send the x-value of the accelerometer with the label “xaccel.”
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image9-1-768x409.png))CHALLENGE
Modify the code above so that it also sends the y-value of the accelerometer with the label “yaccel.”
Click Here to see example code.
Receiving Labeled Values with Radio
The rover can receive the values from the sending micro:bit using the on radio received block that contains two variables, name and value. For example, the code below checks to see if the name of the value is “xaccel.” If it is, then the program loads the value into a variable called xaccel.
Remember, both the rover and the micro:bit sending messages must be set to the same radio group.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image14-1.png))CHALLENGE
Modify the code above so that when it receives a value labeled “yaccel,” it loads the value into a variable with the same name.
Click Here to see example code.
Using Acceleration Variables
Now that the rover is receiving the accelerometer values from the sending micro:bit, we can use them to control the rover. As an example, this code uses the yaccel variable to control the speed of rotation servo 1. Notice that the accelerometer value is divided by 10 to get a value between -100 and 100, the limits of the rotation servo speed.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image31-768x431.png))CHALLENGE
Write a program that moves the rover forward or backward using the x-axis of the accelerometer.
Click Here to see example code.
Using Two Acceleration Variables
Now that you are using the yaccel variable to move forward and back, it would be nice to use the xaccel variable to turn the rover. However, first you have to decide if the robot should be turning. You can do this based on which acceleration value is larger. If the absolute value of yaccel is larger than the absolute value of xaccel, then the robot should move in a straight line. Otherwise, the robot should turn.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image32-768x334.png))CHALLENGE
Use the sample code above to write a program that moves the robot forward or backward using the yaccel variable when absolute yaccel value is larger than the absolute xaccel value. Otherwise, the robot should turn left or right using the xaccel variable.
Click Here to see example code.
Rover: Compass
In this module, you will learn to use the compass that is on the micro:bit to make your robot move in a particular direction.
The compass tells you the direction of your micro:bit relative to magnetic north. You can make your rover drive north while avoiding obstacles!
The Compass Heading Block
Use the compass heading block on the Input menu to read the value of the compass.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image12-1.png))This value will be between 0° and 359°. 0° corresponds to the direction of magnetic north. The angle increases as the robot turns clockwise, so 90° is east, 180° is south, and 270° is west.
To use the compass, the micro:bit must be positioned so that the LED display is parallel to the ground. Otherwise, the compass will not provide useful measurements. When you use the compass, the micro:bit will prompt you to tilt it to calibrate the compass.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image14-768x649.png))CHALLENGE
Write a program that displays the value of the compass on the micro:bit screen when you press button A. Examine how this value changes as you turn the rover.
Click Here to see example code.
Displaying Direction
You can use the compass to make the rover tell you the direction it is heading in.
For example, if the value of the compass is between 45 and 135, print “E” on the micro:bit screen.
You can use the and block on the Logic menu to combine comparisons. The and block will be true only when both Boolean blocks inside it are true.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image16-1-768x283.png))CHALLENGE
Add a second if else block to your script as shown. Modify the nested if else so that the micro:bit says “S” when the value of the compass is between 135 and 225.
Click Here to see example code.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image32-768x334.png))Driving with the Compass
You can also use the compass to make the rover move in a particular direction. For example, this code makes the robot turn clockwise when the compass is less than 180° and counterclockwise otherwise. Try placing the rover in different positions before running this script. Which direction does the rover drive in?
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image30.png))CHALLENGE
Modify your program so that the robot drives south as long as there is no obstacle in the way. When the robot encounters an obstacle, it should back up and turn.
Click Here to see example code.
Making a Line Tracking Sensor
You will use a single color LED and a light sensor to create a line tracking sensor. To track a black line on a light-colored surface, you need to know whether the sensor is over a black surface or a white surface. You can determine this by measuring the amount of light reflected by the surface. A white (or light-colored) surface reflects a lot of light, while a black surface reflects very little light.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/linetracking-schematic-768x475.png))In addition to a single color LED and a light sensor, you will need a piece of cardboard that is roughly 8 cm by 15 cm and a metal brad.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/build1-768x564.png))Poke holes in the cardboard so that you can mount the LED and the light sensor close together along one of the long edges of the cardboard. Use the metal brad to hold the light sensor in place.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/build2-768x534.png))Glue the piece of cardboard to the bottom of the rover’s rotation servos, the LED and the light sensor should be pointing at the ground and 1-2 cm away from the ground.
Connect the single color LED to LED port 1 and the light sensor to sensor port 2.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/build3-768x283.png))Making a Line to Track
To create a line to track, you will need large sheets of white paper and black electrical tape about 2 cm wide. Use the tape to make a black line on a white background. Avoid sharp turns; it is easier for the rover to follow gradual curves.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2019/12/image1-7-1.png))Basic Line Tracking
To track a line, the rover should turn right or left based on whether or not it detects the line. Let’s think about tracking the left side of the line as the rover moves clockwise around the loop. When the line sensor is over the black line, the rover should turn left. When the line sensor is over the white line, the rover should turn right.
Notice that this sample code uses the rotation servos to turn using only one wheel at a time. This means that both turns move the robot slightly forward. As the program repeats the if else block over and over, the rover will follow the line as it turns back and forth.
Note: Rotation servos can vary a lot, so what is a slow speed for one motor may not be for another motor. For example, in the sample code one motor is running at 20% while the other runs at -50%.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/makecodelinetrack1-768x604.png))CHALLENGE
Try out this code. You may need to adjust the line sensor threshold; use the upper-right script that prints the value of the light sensor when you press button A. You may also need to adjust and the turning speed of each rotation servo in order to track your line.
More Line Tracking
You can combine line tracking with other robot behaviors to make more complex programs! For example, the robot can track the line only until it finds an obstacle or hears a loud noise.
CHALLENGE
Write a program that makes the rover track a line but stops the rover when there is an obstacle in front of it.
Click Here to see example code.
Flower: Sensor Control
In this module, you will write MakeCode programs to control a robotic flower. You will need a flower for this module, so use these instructions to build one if you haven’t already.
You should also connect a dial sensor to sensor port 1 for this module.
Note: The flower modules assume that you have already completed the modules in the Inputs and Outputs sections.
The Dial Sensor
You will start by using the Bit dial sensor to control the LEDs.
A convenient way to see the value of the sensor is to use the show number block on the Basic menu. Use an on button pressed block to display the value of the sensor on the screen when you press button A.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image12-5-768x180.png))CHALLENGE
Use the dial to control the brightness of the single color LEDs.
Click Here to see example code.
Math Blocks with the Dial
You can also use the blocks on the Math menu to change the behavior of your program. For example, this program will also make tri-color LED 1 gradually change from blue to red as you turn the dial from 0 to 100.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image19-5-768x547.png))CHALLENGE
Modify your project as follows:
- LED 2 should go from fully on to fully off as you turn the dial from 0 to 100.
- Tri-color LED 2 should change from red to blue as you turn the dial from 0 to 100.
Click Here to see example code.
The Accelerometer
You can also use the accelerometer to control how much the flower blooms.
The micro:bit accelerometer measures how much the micro:bit is tilting in three different directions, which are called x, y, and z. The value of the acceleration is between -1024 mg and 1024 mg for each direction.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/microbitaccel-768x388.png))You can measure the acceleration in the x, y, and z directions using the acceleration block on the Input menu.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image22-4.png))CHALLENGE
Write a program to see the x-value of the accelerometer change as you tilt the Hummingbird in different directions. For an extra challenge, display the y– and z-values of the accelerometer as well.
Click Here to see example code.
Math Blocks with the Accelerometer
The x-value of the acceleration is between -1024 and 1024. To make the flower bloom, we want to use this value to calculate an angle for the position servo.
For example, if we calculate the angle by dividing the x-value of the acceleration by 25 then as the x-value of the acceleration changes from 0 to 1024, the angle will change from 0° to about 41°.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image5-5-768x673.png))CHALLENGE
Adjust the program so that the flower fully blooms as you tilt the Hummingbird Bit to the left (so that the sensor ports are toward the table and the LED ports point toward the ceiling).
Click Here to see example code.
CHALLENGE
The flower doesn’t bloom when you tilt the Bit to the right because the micro:bit x-acceleration is less than 0. How can you make your flower bloom when you tilt the Bit to the right or left?
Hint: You can do this using an if else block or a block from the Math menu.
Click Here to see example code.
Flower: Control with Variables
In the previous module, you used the dial and the micro:bit accelerometer to make the flower bloom and its lights dim, brighten, and change colors.
In this module, you will program the flower to do these things automatically.
The repeat Block
You have been using forever loops to repeat blocks. You can also use the repeat block on the Loops menu.
This block repeats whatever is inside it a certain number of times.
For example, this code will make an LED turn on and off 10 times.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image13-4-768x509.png))CHALLENGE
Write a program to make the flower open and close 5 times.
Click Here to see example code.
Loops with Variables
To make the flower bloom gradually, you will use the repeat block with a variable. A variable is a name that represents a value. You can use it to store information.
Go to the Variables menu and click Make a Variable. Name your variable count.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image6-5.png))You will notice that the Variables menu looks different now. It contains a block for your variable and blocks to change its value.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image8-6.png))CHALLENGE
Try out this code and watch the value of count. What does the change by block do? How does the value of count at the end of the script depend on the number in the repeat block?
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image1-6.png))Loops with Variables
Make your flower bloom gradually using the repeat block and count. Set the number in the repeat block to be the “full bloom” angle for your flower (yours may be different than 90°). Each time through the loop, set the position servo to count and stop briefly. You can vary the length of the wait to make your flower bloom more slowly.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image3-5.png))To make the flower bloom repeatedly, place the code inside a forever loop.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image21-5.png))CHALLENGE
With one repeat block, the flower blooms gradually and then closes quickly. To make the flower close gradually as well, add a second repeat block. Make the angle of the servo go from 90° to 0° by changing count by -1.
Click Here to see example code.
Adding Loops
You can also use a variable to change the color of the tri-color LEDs.
Add a second variable and a second forever loop with a repeat inside. To make the LED change from green to red, use a subtraction block to make green decrease from 100 to 0 as red increases from 0 to 100.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image18-5.png))CHALLENGE
Add two more repeat blocks to your tri-color LED script. Make the LED change from green to red, then red to blue, then blue back to green. Make the program repeat this sequence until you press the stop button.
Click Here to see example code.
CHALLENGE
Add two more repeat blocks to your tri-color LED script. Make the LED change from green to red, then red to blue, then blue back to green. Make the program repeat this sequence until you press the stop button.
Click Here to see example code.
For Loops
MakeCode also contains a loop called a for loop.The for block on the Loops menu is a loop that creates a variable called index. The variable index automatically changes from the first value specified in the for block to the second. Each time through the loop, the value of index automatically changes by one. This means that this program also gradually changes tri-color LED 1 from green to red! In this lesson, we focus on declaring our own variables, but you can explore how to use for blocks in your Hummingbird programs.
((img class=img-responsive src=https://learn.birdbraintechnologies.com/wp-content/uploads/2020/10/image7-6.png))CHALLENGE
Make the flower gradually bloom and close using for loops.
Click Here to see example code.