Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Circuit Playground Express Demo Code
5# Adjust the pulseio 'board.PIN' if using something else
6import pulseio
7import board
8import adafruit_irremote
9
10pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
11decoder = adafruit_irremote.GenericDecode()
12
13
14while True:
15 pulses = decoder.read_pulses(pulsein)
16 print("Heard", len(pulses), "Pulses:", pulses)
17 try:
18 code = decoder.decode_bits(pulses)
19 print("Decoded:", code)
20 except adafruit_irremote.IRNECRepeatException: # unusual short code!
21 print("NEC repeat!")
22 except (
23 adafruit_irremote.IRDecodeException,
24 adafruit_irremote.FailedToDecode,
25 ) as e: # failed to decode
26 print("Failed to decode: ", e.args)
27
28 print("----------------------------")