Use Map so the buzzer sounds higher the closer an object gets.
This tutorial is part of the Nairda learning path. You can build it step by step inside the app, which checks every block you place before letting you move on.
The steps
- We create an ultrasonic called sensor, trigger on 10 and echo on 11.
- We create a frequency called buzzer on pin 8.
- We create a number variable called tone.
- We add a While loop, which repeats forever.
- Inside the loop we set tone to a Map block.
- What we map is the sensor reading.
- The distance comes in between 0 and 100 centimeters.
- And goes out as a tone between 200 and 2000 hertz.
- Behind it we put the buzzer and give it the tone variable.
When you finish, the app takes you straight to the next tutorial in the path.