CircuitPython IR Remote in loop

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Neuralian
 
Posts: 2
Joined: Sun May 09, 2021 1:40 am

CircuitPython IR Remote in loop

Post by Neuralian »

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?

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: CircuitPython IR Remote in loop

Post by mikeysklar »

@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

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() 

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”