/ examples / irremote_simpletest.py
irremote_simpletest.py
 1  # Circuit Playground Express Demo Code
 2  # Adjust the pulseio 'board.PIN' if using something else
 3  import pulseio
 4  import board
 5  import adafruit_irremote
 6  
 7  pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
 8  decoder = adafruit_irremote.GenericDecode()
 9  
10  
11  while True:
12      pulses = decoder.read_pulses(pulsein)
13      print("Heard", len(pulses), "Pulses:", pulses)
14      try:
15          code = decoder.decode_bits(pulses)
16          print("Decoded:", code)
17      except adafruit_irremote.IRNECRepeatException:  # unusual short code!
18          print("NEC repeat!")
19      except adafruit_irremote.IRDecodeException as e:  # failed to decode
20          print("Failed to decode: ", e.args)
21  
22      print("----------------------------")