-
Notifications
You must be signed in to change notification settings - Fork 776
/
Copy pathcode.py
34 lines (30 loc) · 1.21 KB
/
code.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
29
30
31
32
33
34
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import pulseio
import board
import adafruit_irremote
# Create a 'pulseio' input, to listen to infrared signals on the IR receiver
pulsein = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True)
# Create a decoder that will take pulses and turn them into numbers
decoder = adafruit_irremote.GenericDecode()
while True:
pulses = decoder.read_pulses(pulsein)
try:
# Attempt to convert received pulses into numbers
received_code = decoder.decode_bits(pulses)
except adafruit_irremote.IRNECRepeatException:
# We got an unusual short code, probably a 'repeat' signal
# print("NEC repeat!")
continue
except adafruit_irremote.IRDecodeException as e:
# Something got distorted or maybe its not an NEC-type remote?
# print("Failed to decode: ", e.args)
continue
print("NEC Infrared code received: ", received_code)
if received_code == [255, 2, 255, 0]:
print("Received NEC Vol-")
if received_code == [255, 2, 127, 128]:
print("Received NEC Play/Pause")
if received_code == [255, 2, 191, 64]:
print("Received NEC Vol+")