-
Notifications
You must be signed in to change notification settings - Fork 776
/
Copy pathcode.py
32 lines (29 loc) · 1.12 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
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
from adafruit_circuitplayground.express import cpx
import adafruit_irremote
import pulseio
import board
# Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz
pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)
# Create an encoder that will take numbers and turn them into NEC IR pulses
encoder = adafruit_irremote.GenericTransmit(header=[9000, 4500],
one=[560, 1700],
zero=[560, 560],
trail=0)
while True:
if cpx.button_a:
print("Button A pressed! \n")
cpx.red_led = True
encoder.transmit(pulseout, [255, 2, 255, 0])
cpx.red_led = False
# wait so the receiver can get the full message
time.sleep(0.2)
if cpx.button_b:
print("Button B pressed! \n")
cpx.red_led = True
encoder.transmit(pulseout, [255, 2, 191, 64])
cpx.red_led = False
time.sleep(0.2)