PA Designer Learn 2: LED and Loudness Sensor
8. Test: Loudness Sensor
Now we’re ready to code up the sensor reading loop. We no longer need the code that we wrote to test the LED so
- let’s clear this code from the Main Code cell.
- Now type the following code into it
# perform all variable declaration and initialization
init()
# repeat the following instructions for 10 seconds
while elapsed_time() < 10:
print (f“Loudness = {loudness.read()}”)
time.sleep(0.02)
Click on Run Selected Cell.
If everything is in order, you should see a stream of loudness readings displayed below the code cell (your numbers will be different):
Loudness = 171
Loudness = 126
Loudness = 314
If you don’t get any readings, run through the troubleshooting steps, noting that we are using port “AD2” for the loudness sensor, and try again.
- Have you plugged the Loudness Sensor board into the Analog Digital 2 port?
- Does your code initialize the Loudness Sensor using port “AD2”?
- Are both ends of the connector cable fully inserted?