forked from adafruit/Adafruit_CircuitPython_IRRemote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirremote_simpletest.py
28 lines (23 loc) · 873 Bytes
/
irremote_simpletest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# Circuit Playground Express Demo Code
# Adjust the pulseio 'board.PIN' if using something else
import pulseio
import board
import adafruit_irremote
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()
while True:
pulses = decoder.read_pulses(pulsein)
print("Heard", len(pulses), "Pulses:", pulses)
try:
code = decoder.decode_bits(pulses)
print("Decoded:", code)
except adafruit_irremote.IRNECRepeatException: # unusual short code!
print("NEC repeat!")
except (
adafruit_irremote.IRDecodeException,
adafruit_irremote.FailedToDecode,
) as e: # failed to decode
print("Failed to decode: ", e.args)
print("----------------------------")