PA Designer Learn 2: LED and Loudness Sensor
3. Code: Instantiation
We are now ready to create instances of the sensor and LED classes and give them the names loudness and led for ease of reference later on. Type the following code into the code cell labelled Sensor Setup Code in the template notebook you have just uploaded.
Fill the Sensor Setup code cell:
# initialize loudness sensor object (attached to Analog Digital 2)
loudness = assistant.init_loudness_sensor("AD2")
# initialize LED object (attached to Analog Digital 1)
led = assistant.init_led("AD1")
# set the LED’s starting state to OFF
led.light_off()
The EasyGoPiGo3 class library contains init_ functions for many add-ons (e.g. init_led()). These functions create an instance and do a lot of the hard work of initializing important add-on settings for us. All we have to do is say which port we have attached the add-on to.