Snap! Project 4: Dimmer LED and Servo
Description: Control a servo and LED with a rotation sensor
Programming Concepts: using sensors to control Hummingbird outputs
Materials: Hummingbird Controller, LED, Rotation Sensor, Servo
Approx. Time: 30 Minutes
1. Connect the tri-color LED to port 1.
2. Attach the servo to servo port 1.
3. Connect the rotation sensor to sensor port 1.
4. Plug the Hummingbird into a wall socket and into your computer.
To make a dimmer switch, we want the brightness of the LED to depend on the output of the rotation sensor.
1. Drag an LED block from the "Looks" category to the middle of your screen.
2. The intensity of the LED should be determined by reading the rotation sensor. The output of the rotation sensor ranges from 0 to 100. Likewise, the LED block accepts an intensity from 0 to 100. This means we can simply insert the "Hummingbird Knob" block into the intensity slot of the LED block.
3. We want the LED's intensity to be continuously set to the current value of the rotation sensor. Add a forever loop (from the "Control" category) around the LED block to do this.
4. Click the loop to start the program. Turn the rotation sensor and the LED should fade on and off.
5. Stop the program using the red stop sign.
6. Now let's make the rotation sensor control the servo as well. Add a servo block below the LED block.
7. The servo block accepts an angle from 0 to 180 while the rotation sensor can only produce an output from 0 to 100. To fix this, we need to multiply the rotation sensor's output by 1.8 (because 100*1.8=180). Drag a multiplication block from the "Operators" category to achieve this.
8. Type the value 1.8 into the first slot of the multiplication block.
9. Add a "Hummingbird Knob" block into the second slot of the multiplication block.
10. Click the forever loop to start the program. You can now control both the LED and the servo by turning the rotation sensor.
This file was created with the Birdbrain Robot Server. Use this utility to convert it to a form that can be used with the Chrome Finch connection app.