PA Designer Learn 2: LED and Loudness Sensor
This is the second challenge within the Robotics with GoPiGo and Python Curriculum.
Your task is to program your robot to alert a person with a hearing impairment to visiting house guests.
Learn how to use the Loudness Sensor alongside Jupyter Notebooks.
6. Test: Loudness Sensor
To test the loudness sensor, let’s write some code to repeatedly take sensor readings for 10 seconds, reporting the values read as we go.
To help with this task, we have provided you with an elapsed_time() function. This measures the time difference, in seconds, between the moment that it is called and a reference time stored in a start_time variable. We need to declare this start_time variable and initialize it when we start our program by assigning the result of a time check to it.
There is an empty function in the Variable Initialization cell, called init(). Except it's not entirely empty! It has the keyword pass, which is just a placeholder for future code. Remove that pass keyword.
Within the now empty init() function , type the following code. We won’t run this code just now. Instead, we will be inserting a call to this function at the start of our Main Code cell to set everything up every time we run that cell.
Variable Initialization cell:
def init():
# declare global variables that will be used by our program
global start_time
# perform a time-check at the start of our program
start_time = time.time()