User Manual

53
pLed.ChangeDutyCycle(dc) # ChangeDutyCycle() function in pLED output
pulse width 0~100% according to the variable dc.
print " ++ Duty cycle: %s"%dc # print information
time.sleep(delay) # it will delay after changing the pulse width for
each time, this parameter can be modified to change the LED’s lighting and dimming
speed.
time.sleep(1)
# decrease duty cycle from 100 to 0
for dc in range(100, -1, -step): # the luminance of the LED decreases with each
cycle.
# Change duty cycle to dc
pLED.ChangeDutyCycle(dc) # same as the last for loop
print " -- Duty cycle: %s"%dc
time.sleep(delay)
Now you w ill see the gradual change of the LED luminance, between bright and dim.
Summary
Through this experiment, you should have mastered the principle of PWM and how to
program Raspberry Pi with PWM. You can try to apply this technology to DC motor speed
regulation later.
SunFounder