Skip to content

Instantly share code, notes, and snippets.

@jedgarpark
Last active December 17, 2017 08:49
Show Gist options
  • Save jedgarpark/f948374436a520b14407a9241dc8aab8 to your computer and use it in GitHub Desktop.
Save jedgarpark/f948374436a520b14407a9241dc8aab8 to your computer and use it in GitHub Desktop.
import pulseio
import board
import adafruit_irremote
from adafruit_circuitplayground.express import cpx
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()
import time
# size must match what you are decoding! for NEC use 4
received_code = bytearray(4)
# IR Remote Mapping
'''
1: [255, 2, 247, 8]
2: [255, 2, 119, 136]
3: [255, 2, 183, 72]
4: [255, 2, 215, 40]
5: [255, 2, 87, 168]
6: [255, 2, 151, 104]
7: [255, 2, 231, 24]
8: [255, 2, 103, 152]
9: [255, 2, 167, 88]
0: [255, 2, 207, 48]
^ : [255, 2, 95, 160]
v : [255, 2, 79, 176]
> : [255, 2, 175, 80]
< : [255, 2, 239, 16]
Enter: [255, 2, 111, 144]
Setup: [255, 2, 223, 32]
Stop/Mode: [255, 2, 159, 96]
Back: [255, 2, 143, 112]
Vol - : [255, 2, 255, 0]
Vol + : [255, 2, 191, 64]
Play/Pause: [255, 2, 127, 128]
'''
pixel_bright = 0.02
RED = (255, 0, 0)
GREEN = (0, 255, 0)
WHITE = (85, 85, 85)
BLUE = (0, 0, 255)
PINK = (128, 0, 128)
YELLOW = (148, 108, 0)
PURPLE = (200, 0, 55)
TEAL = (0, 200, 100)
BLACK = (0, 0, 0)
while True:
cpx.red_led = False
pulses = decoder.read_pulses(pulsein)
cpx.red_led = True
print("Heard", len(pulses), "Pulses:", pulses)
try:
code = decoder.decode_bits(pulses,debug=False)
print("Decoded:", code)
except adafruit_irremote.IRNECRepeatException: # unusual short code!
print("NEC repeat!")
except adafruit_irremote.IRDecodeException as e: # failed to decode
print("Failed to decode: ", e.args)
continue
print("----------------------------")
time.sleep(0.1)
cpx.red_led = False
cpx.pixels.brightness = pixel_bright
command = code[2]
if command == 247: # 1
cpx.pixels.fill(RED)
if command == 119: # 2
cpx.pixels.fill(GREEN)
if command == 183: # 3
cpx.pixels.fill(WHITE)
if command == 215: # 4
cpx.pixels.fill(BLUE)
if command == 87: # 5
cpx.pixels.fill(PINK)
if command == 151: # 6
cpx.pixels.fill(YELLOW)
if command == 231: # 7
cpx.pixels.fill(PURPLE)
if command == 103: # 8
cpx.pixels.fill(TEAL)
if command == 207 :
cpx.pixels.fill(BLACK)
if command == 95: # up
pixel_bright = 1
cpx.pixels.show()
if command == 79: # down
pixel_bright = 0.005
cpx.pixels.show()
if command == 111: # down
pixel_bright = 0.02
cpx.pixels.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment