def blink(self, on=1, off=-1):
"""Blinks an LED by working out the correct PWM frequency/duty cycle
@param self Object pointer.
@param on Time the LED should stay at 100%/on
@param off Time the LED should stay at 0%/off"""
self.stop()
if off == -1:
off = on
off = float(off)
on = float(on)
total = off + on
duty_cycle = 100.0 * (on/total)
# Use pure PWM blinking, because threads are ugly
self.frequency(1.0/total)
self.duty_cycle(duty_cycle)
self.blinking = True
return True
评论列表
文章目录