Simple test

Ensure your device works with this simple test.

examples/irremote_simpletest.py
 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 board
 7import pulseio
 8
 9import adafruit_irremote
10
11pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
12decoder = adafruit_irremote.GenericDecode()
13
14
15while True:
16    pulses = decoder.read_pulses(pulsein)
17    print("Heard", len(pulses), "Pulses:", pulses)
18    try:
19        code = decoder.decode_bits(pulses)
20        print("Decoded:", code)
21    except adafruit_irremote.IRNECRepeatException:  # unusual short code!
22        print("NEC repeat!")
23    except (
24        adafruit_irremote.IRDecodeException,
25        adafruit_irremote.FailedToDecode,
26    ) as e:  # failed to decode
27        print("Failed to decode: ", e.args)
28
29    print("----------------------------")