CircuitPython IR Remote in loop
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Neuralian
- Posts: 2
- Joined: Sun May 09, 2021 1:40 am
CircuitPython IR Remote in loop
Using IRRemote GenericDecoder in a loop pauses when an IR remote key is held down, even with blocking=False. Is there a way/workaround so that I can read a stream of codes from an IR remote, and keep doing other stuff in a loop?
- mikeysklar
- Posts: 13824
- Joined: Mon Aug 01, 2016 8:10 pm
Re: CircuitPython IR Remote in loop
@Neuralian,
Since CircuitPython does not provide built interrupts and our IR library is minimal you should take a look at Chris Young's IRlibCP. It looks like you could slip in some "other stuff" you want to run in the "pass" area of the main loop in this example.
https://github.com/adafruit/IRLibCP
https://github.com/adafruit/IRLibCP/blo ... ultiple.py
Since CircuitPython does not provide built interrupts and our IR library is minimal you should take a look at Chris Young's IRlibCP. It looks like you could slip in some "other stuff" you want to run in the "pass" area of the main loop in this example.
https://github.com/adafruit/IRLibCP
https://github.com/adafruit/IRLibCP/blo ... ultiple.py
Code: Select all
# IRLibCP by Chris Young. See copyright.txt and license.txt
# Sample program to decode multiple protocols.
# In this case NEC, Sony and RC5
import board
import IRLibDecodeBase
import IRLib_P01_NECd
import IRLib_P02_Sonyd
import IRLib_P03_RC5d
import IRrecvPCI
class MyDecodeClass(IRLibDecodeBase.IRLibDecodeBase):
def __init__(self):
IRLibDecodeBase.IRLibDecodeBase.__init__(self)
def decode(self):
if IRLib_P01_NECd.IRdecodeNEC.decode(self):
return True
if IRLib_P02_Sonyd.IRdecodeSony.decode(self):
return True
elif IRLib_P03_RC5d.IRdecodeRC5.decode(self):
return True
else:
return False
myDecoder=MyDecodeClass()
myReceiver=IRrecvPCI.IRrecvPCI(board.REMOTEIN)
myReceiver.enableIRIn()
print("send a signal")
while True:
while (not myReceiver.getResults()):
pass
if myDecoder.decode():
print("success")
else:
print("failed")
myDecoder.dumpResults(True)
myReceiver.enableIRIn()
Please be positive and constructive with your questions and comments.