How to turn on and off a pwm pulsed IR LED
Posted: Wed Oct 29, 2014 1:10 pm
I will implement an infrared protocol with the pyboard.
Therefore i need to turn on and off a pwm pulsed IR LED.
What i did so far:
I didn't found a better way to turn on and off the LED, but this solution works so far. The problem is, that i will toggle the LED inside an timer interrupt. But the implementation of the On method creates a new timerChannel object, what is not allowed.
Is there a way, to create the timer once in the init method and then switch the timer on and off?
Therefore i need to turn on and off a pwm pulsed IR LED.
What i did so far:
Code: Select all
class IrLed(object):
def __init__(self, pinId, timerId, timerChannel, freq):
self._timer = pyb.Timer(timerId, freq=freq * 2)
self._timerChannel = timerChannel
self._pinId = pinId
def On(self):
self._timer.channel(self._timerChannel, pyb.Timer.OC_TOGGLE, pin=self._pinId)
def Off(self):
pyb.Pin(self._pinId, mode=pyb.Pin.OUT_OD, pull=pyb.Pin.PULL_DOWN)
irLed = IrLed(pyb.Pin.board.Y1, 8, 1, 56000)
Is there a way, to create the timer once in the init method and then switch the timer on and off?