Use of Lego Mindstorm Sensor Analog Data


We have this project were doing - this is one of the problems: “For this lab you are going to add sensors to your car so that it responds to the environment. First, add a touch sensor which will stop the car when pressed. Next add a sound sensor so that a loud sound (like clapping) will cause it to go in reverse and a second loud sound will reverse it again. Submit a commented *.py code file.”

I have written a code for the touch sensor, as it is easy enough to use the data as it is digital. However, the data that reads from the sound sensor is analog, and I am completely lost. I’m not sure how to code the sensor to read a loud sound, and then respond to that with changing the speed. Is there a function that interperets the analog data of the sound sensors (SENSOR_TYPE_RAW)?

Thanks for your help. Starting to get frustrated

Hello Tim,
Sounds like you’re using the BrickPi, is that right? In Python?

Have you had a look at this example file: