code.py
 1  # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  from adafruit_circuitplayground.express import cpx
 7  import adafruit_irremote
 8  import pulseio
 9  import board
10  
11  # Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz
12  pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)
13  # Create an encoder that will take numbers and turn them into NEC IR pulses
14  encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550],
15                                              zero=[550, 1700], trail=0)
16  
17  while True:
18      if cpx.button_a:
19          print("Button A pressed! \n")
20          cpx.red_led = True
21          encoder.transmit(pulseout, [255, 2, 255, 0])
22          cpx.red_led = False
23          # wait so the receiver can get the full message
24          time.sleep(0.2)
25      if cpx.button_b:
26          print("Button B pressed! \n")
27          cpx.red_led = True
28          encoder.transmit(pulseout, [255, 2, 191, 64])
29          cpx.red_led = False
30          time.sleep(0.2)