Skip to content

Commit 1420420

Browse files
authored
Merge pull request #2214 from adafruit/ir_owl
Adding IR owl remote code
2 parents 43cd470 + 233f19a commit 1420420

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Owl_IR_TV_Remote/code.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import array
5+
import pulseio
6+
import pwmio
7+
import board
8+
from digitalio import DigitalInOut, Direction, Pull
9+
from adafruit_debouncer import Debouncer
10+
import neopixel
11+
12+
# button setup with Debouncer
13+
pin = DigitalInOut(board.A2)
14+
pin.direction = Direction.INPUT
15+
pin.pull = Pull.UP
16+
button = Debouncer(pin)
17+
18+
# button LED
19+
led = DigitalInOut(board.A1)
20+
led.direction = Direction.OUTPUT
21+
22+
# onboard neopixel
23+
pix = board.NEOPIXEL
24+
num_pixels = 1
25+
pixel = neopixel.NeoPixel(pix, num_pixels, brightness=0.8, auto_write=False)
26+
27+
# PWM setup for IR LEDs
28+
pwm = pwmio.PWMOut(board.TX, frequency=38000, duty_cycle=2**15)
29+
remote = pulseio.PulseOut(pwm)
30+
# power on pulse array
31+
power_on = array.array('H', [9027, 4490, 577, 563, 549, 1677, 579, 1674, 582, 558,
32+
554, 559, 553, 561, 551, 562, 551, 1675, 580, 1674, 572,
33+
567, 555, 1672, 573, 567, 556, 558, 554, 559, 553, 560,
34+
552, 562, 550, 1675, 581, 560, 552, 561, 552, 561, 551,
35+
563, 549, 1677, 579, 1674, 581, 560, 552, 561, 552, 1674,
36+
581, 1673, 573, 1680, 575, 1679, 577, 563, 549, 565, 547,
37+
1679, 577])
38+
# power off pulse array
39+
power_off = array.array('H', [9028, 4491, 576, 563, 549, 1678, 578, 1701, 554, 533,
40+
579, 561, 551, 562, 551, 536, 576, 1703, 552, 1700, 556,
41+
558, 554, 1698, 547, 540, 582, 558, 554, 532, 580, 560,
42+
552, 561, 552, 562, 550, 563, 549, 564, 548, 565, 547,
43+
566, 546, 1707, 549, 1704, 551, 562, 550, 1703, 553, 1699,
44+
556, 1697, 548, 1705, 551, 1701, 554, 560, 553, 560, 552,
45+
1701, 554])
46+
# array of the pulses
47+
signals = [power_on, power_off]
48+
# neopixel colors
49+
RED = (255, 0, 0)
50+
GREEN = (0, 255, 0)
51+
# array of colors
52+
colors = [GREEN, RED]
53+
# index variable
54+
s = 0
55+
56+
while True:
57+
# scan button for update
58+
button.update()
59+
# if the button is pressed..
60+
if button.fell:
61+
# send the pulse
62+
remote.send(signals[s])
63+
# update onboard neopixel
64+
pixel.fill(colors[s])
65+
pixel.show()
66+
# turn on button LED
67+
led.value = True
68+
# advance the index variable
69+
s = (s + 1) % 2
70+
# if the button is released..
71+
if button.rose:
72+
# turn off the button LED
73+
led.value = False

0 commit comments

Comments
 (0)