# BirdBlox: Lessons for Hummingbird (Part 2)

#### Module 6: Rotary Knob

The rotary knob is another sensor; this sensor measures how much you have turned the knob. You can use the Duo Knob block to find the value of this sensor. This value will be between 0 and 100. Always remember to make sure that the Duo Knob block is set to the port attached to the rotary knob.

#### Exercise 6.1

Attach the knob to the Hummingbird board. Write a script that continually displays the value of the Duo Knob block. Then turn the knob all the way to the left. What is the value of the Duo Knob block? What is the value of the Duo Knob block when the knob is turned all the way to the right?

#### Exercise 6.2

Write a program that turns on a single color LED when the knob is turned far enough to the left. When the knob is turned far enough to the right, the LED should be off. What will your threshold be for this program? Remember, the threshold is the value that the Boolean block uses to make a decision.

In the previous exercise, you used the rotary knob to decide whether the LED should be on or off. Instead, you could use the knob to determine the brightness of the LED. Because the Duo Knob block is a number between 0 and 100, you can place it inside the Duo LED block to set the intensity of the light. Try out the script below. The forever loop repeatedly changes the brightness of the LED to match the value of the knob.

#### Exercise 6.3

Use the knob to control a gear motor and the amount of red in a tri-color LED (the amount of green and blue can be whatever you want). These components should change at the same time.

The rotary knob is useful for controlling the LEDs because its range (0-100) is the same as the input range for these components. If you place the knob block inside the Duo Servo block, as shown below, the servo will only move from 0° to 100°.

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

#### Exercise 6.4

Place the Duo Knob block inside a multiplication block, as shown below. What number should you use instead of 0 so that the knob moves the servo from 0° to 180°? When the value of the knob is 0, the servo should be at 0°. When the value of the knob is 100, the servo should be at 180°.

#### Exercise 6.5

What do you think the script below will do? Make a prediction before you try it out.

#### Programming Tip

Don’t forget to set the port in the sensor block to the port on the Hummingbird board that you are actually using! If the value of the sensor is not changing as expected, be sure to check that the sensor block is reading the correct port.

#### Module 7: Light Sensor and Putting It All Together

The light sensor measures the amount of light around it. This sensor is very similar to the other sensors that you have learned about. You can use the Duo Light block to find the value of this sensor. This value will be between 0 and 100. Always remember to make sure that the Duo Light block is set to the appropriate port.

#### Exercise 7.1

Attach the light sensor to the Hummingbird board. Use the Duo Light block to measure the amount of light in your room. Then measure the value of the light sensor when you cover it with your hand. The average of these two values is a good threshold for the light sensor.

#### Exercise 7.2

Write a script that turns on a vibration motor when the light sensor detects that it is dark. Otherwise, the vibration motor should be off.

You have now practiced using all the Hummingbird motors and lights, as well as three of the sensors. There are other sensors, including a temperature sensor and a sound sensor. These work very similarly to the sensors you have already used. The Duo Temperature C block tells you the temperature in Celsius, and the Duo Sound block tells you the amount of noise around the Hummingbird on a scale of 0-100.

The last two exercises below will give you some practice using multiple sensors. After you have completed these, you will be ready to create many exciting, unique Hummingbird robots!

#### Exercise 7.3

Write a program that uses the knob sensor to control the color of a tri-color LED. However, the LED should only be on when an object is less than 30 cm from the distance sensor. Otherwise, the LED should be off.

#### Exercise 7.4

Write a program that sends the servo to four different angles based on the values of the distance and light sensors. All of the values are shown in the table below.

 Distance Light Servo Angle Greater than 20 cm Above the threshold 0° Greater than 20 cm Below the threshold 60° Less than 20 cm Above the threshold 120° Less than 20 cm Below the threshold 180°

Congratulations! You have completed Hummingbird BirdBlox training. Have fun making robots!