create our very own custom sound gauge.
Test it out! Eddie should show a bar on his screen
based on how much sound he hears. If your sound bar
looks crooked, you probably forgot to set the coordinate
values to 0 in Step 3.
Now that you understand the sound sensor a bit
better, here are some fun programming challenge ideas:
• Make a vertical sound gauge.
Sound Gauge Program Instructions
Figure 1. Create a program called Sound_Gauge. Start with a loop
inside a loop. On the inner loop, set the Control to Count, and the
Count to 5. This means that the inner loop will run five times per
cycle. We're going to use one loop per pixel width of our sound
gauge; you can adjust this value later.
Figure 2. We have to give our sound gauge X and Y coordinates
to draw itself. Add a math block connected to the output of
the loop, and set the operation to addition and B to 20. This
will ultimately tell Eddie what Y coordinates to draw from. Now
we just need X.
Figure 3. Add a sound sensor block set to port 2, a display
block with Action set to Drawing, and Type set to Line. Set all
the coordinates to 0, and expand the data hub.
Figure 4. Run a data wire from the output of the math block to
the end point Y data port, and another data wire from the
output of the sound sensor block to the input of the end point
X data port.
SERVO 09.2011 65