PA Designer Learn 2: LED and Loudness Sensor

4. Test: LED

To test the LED, let’s write some code to flash it on and off a number of times. In the Main Code cell of our notebook, type the following code:

Main Code cell:

for i in range (1,5):
    # turn on LED at maximum brightness
    led.light_max() 
    time.sleep(0.5)

    # set LED to 30% brightness
    led.light_on(30)  
    time.sleep(0.5)

    # turn LED off
    led.light_off() 
    time.sleep(0.5)

Click on Run Selected Cell.

This demonstrates the range of functions that you can use to switch your LED on and off and adjust its brightness in a range from 0 (off) to 100 (maximum brightness). 

You might also recognize the for loop and time.sleep() instruction from Challenge 1.