So far, you have used sensors to control Hummingbird outputs with if-else statements and while loops. In this lesson, you will learn to use the dial sensor to control Hummingbird outputs directly while practicing while loops with the sound sensor. Start by connecting the dial sensor to port 1, the sound sensor to port 2, and a single color LED to port 1.
Lesson 9 – Dial + Sound Sensors
1 Dial Sensor, 1 Sound Sensor, 1 Single Color LED, 1 Tri-Color LED, 1 Position Servo, 1 Rotation Servo
Use the getDial() method to find the value of the dial sensor, and the getSound() method to find the value of the sound sensor. Just like the other sensor methods you have used, both of these methods require one parameter, the port to which the sensor is connected (1-3). The getDial() method returns a value from 0-100 that represents the position of the dial. The getSound() method returns a value from 0 to roughly 100 that represents the magnitude of the sound around the sensor in arbitrary units.
Note: If your Hummingbird contains a micro:bit V2, you can also use the sound sensor in the micro:bit by calling getSound(“microbit”). Using the “microbit” parameter will result in an error if your Hummingbird does not have a micro:bit V2.
Write a program to use the dial to move the position servo from 0° to 180°.
Write a program to use the dial to gradually change the tri-color LED from red to blue.
Write a program to use the dial to control the rotation servo. When the dial value is 0, the speed of the rotation servo should be -100. When the dial value is 100, the speed of the rotation servo should be 100. Hint: You will need to find a linear equation of the form speed = slope*dial + intercept.
Write a program that uses the sound sensor to control the color of the tri-color LED.