circuitplayground_ir_transmit.py
1 """THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE. 2 This example requires the adafruit_irremote.mpy library. 3 4 This example uses the IR transmitter found near the center of the board. Works with another CPX 5 running the cpx_ir_receive.py example. Press the buttons to light up the NeoPixels on the RECEIVING 6 CPX!""" 7 import time 8 import pulseio 9 import board 10 import adafruit_irremote 11 from adafruit_circuitplayground.express import cpx 12 13 # Create a 'pulseio' output, to send infrared signals from the IR transmitter 14 pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15) 15 pulseout = pulseio.PulseOut(pwm) 16 # Create an encoder that will take numbers and turn them into NEC IR pulses 17 encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550], 18 zero=[550, 1700], trail=0) 19 20 while True: 21 if cpx.button_a: 22 print("Button A pressed! \n") 23 cpx.red_led = True 24 encoder.transmit(pulseout, [66, 84, 78, 65]) 25 cpx.red_led = False 26 # wait so the receiver can get the full message 27 time.sleep(0.2) 28 if cpx.button_b: 29 print("Button B pressed! \n") 30 cpx.red_led = True 31 encoder.transmit(pulseout, [66, 84, 78, 64]) 32 cpx.red_led = False 33 time.sleep(0.2)