import Adafruit_BBIO.PWM as PWM # Configure pin P9_14 as a PWM pin with a frequency of 1000Hz PWM.start("P9_14", 0, 1000) # Set duty cycle to 50% PWM.set_duty_cycle("P9_14", 50) # Stop PWM output PWM.stop("P9_14") PWM.cleanup()
import Adafruit_BBIO.PWM as PWM import time # Configure pin P9_14 as a PWM pin with a frequency of 1000Hz PWM.start("P9_14", 0, 1000) # Sweep the duty cycle from 0% to 100% for i in range(101): PWM.set_duty_cycle("P9_14", i) time.sleep(0.01) # Stop PWM output PWM.stop("P9_14") PWM.cleanup()In this example, we first configure pin P9_14 as a PWM pin with a frequency of 1000Hz. Then, we sweep the duty cycle from 0% to 100% using a loop and set_duty_cycle method. We wait for 0.01s after each step to observe the change in LED brightness. Finally, we stop the PWM output and cleanup the resources used. The package library used in these examples is Adafruit_BBIO.