def __init__(self): self.irout = None self.irtx = None self.encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0)
SCHLIST = [254, 1, 156, 99] YELLOW = [254, 1, 156, 99] SCREEN = [254, 1, 28, 227] BLUE = [254, 1, 28, 227] VOLUP = [254, 1, 220, 35] VOLDOWN = [254, 1, 148, 107] # Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2**15) pulseout = pulseio.PulseOut(pwm) # Create an encoder that will take numbers and turn them into NEC IR pulses encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0) while True: if cpx.button_a: print("Button A pressed! \n") cpx.red_led = True encoder.transmit(pulseout, VOLUP) 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, POWER) cpx.red_led = False
duty_cycle=round(20 / 100 * 65535)) ir_pulseout = pulseio.PulseOut(ir_carrier_pwm) ### Used to observe 6.0.0-6.2.0 bug ### https://github.com/adafruit/circuitpython/issues/4602 ##ir_carrier_pwm_a2debug = pulseio.PWMOut(board.A2, ## frequency=CARRIER_IRFREQ_SONY, ## duty_cycle=round(20 / 100 * 65535)) ##ir_pulseout_a2debug = pulseio.PulseOut(ir_carrier_pwm_a2debug) ### Sony timing values (in us) based on the ones in ### https://github.com/z3t0/Arduino-IRremote/blob/master/src/ir_Sony.cpp ### Disabling the addition of trail value is required to make this work ### trail=0 did not work ir_encoder = adafruit_irremote.GenericTransmit(header=[2400, 600], one= [1200, 600], zero= [600, 600], trail=None) def fire_shutter(): """Send infrared code to fire the shutter. This is a code used by Sony cameras.""" ir_encoder.transmit(ir_pulseout, [0xB4, 0xB8, 0xF0], repeat=2, delay=0.005, nbits=20) ### Send to A2 to help debug issue with 5.3.1 ok, 6.x broken ### ##ir_encoder.transmit(ir_pulseout_a2debug, [0xB4, 0xB8, 0xF0], ## repeat=2, delay=0.005, nbits=20) def say_interval(number_as_words): words = number_as_words.split() + ["seconds"]
import adafruit_irremote from adafruit_circuitplayground.express import cpx ### 38kHz modulation with 50% duty cycle (represented by 2**15==32768) pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2**15) pulseout = pulseio.PulseOut(pwm) ### Create an encoder for NEC IR timed pulses (in microseconds) ### NEC values from Adafruit example - these do work for PCS II ##encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], ## one= [550, 550], ## zero= [550, 1700], ## trail=0) ### Observed values encoder = adafruit_irremote.GenericTransmit(header=[9000, 4500], one=[575, 550], zero=[600, 1650], trail=0) ### Practical Colorful Series II remote for RGBW lightbulbs ### There's clear potential here to store these more neatly ### in a separate per remote control file/database ### generated by ir-decode-to-python.py ircodes = [ [255, 0, 93, 162], [255, 0, 157, 98], [255, 0, 29, 226], [255, 0, 221, 34], [255, 0, 253, 2], [255, 0, 61, 194], [255, 0, 31, 224], [255, 0, 87, 168],
keypad = adafruit_matrixkeypad.Matrix_Keypad(cols, rows, keys) keyPressed = False # IR setup pulsein = pulseio.PulseIn(board.D12, maxlen=120, idle_state=True) decoder = adafruit_irremote.GenericDecode() received_code = bytearray(4) # size must match what you are decoding! for NEC use 4 # Docs for adafruit_irremote: (https://circuitpython.readthedocs.io/projects/irremote/en/latest/api.html#implementation-notes) # Article for IR Apple Remote Code: https://www.hackster.io/BlitzCityDIY/circuit-python-ir-remote-for-apple-tv-e97ea0 # IR Test Code (Apple Remote): https://github.com/BlitzCityDIY/Circuit-Python-Apple-TV-IR-Remote/blob/master/ciruitPython_appleTv_IR-Remote # pwm out test OKAY = bytearray(b'\x88\x1e\xc5 ') #decoded [136, 30, 197, 32] remote = adafruit_irremote.GenericTransmit((9050, 4460), (550, 1650), (570, 575), 575) pwm = pulseio.PWMOut(board.D9, frequency = 38000, duty_cycle = 2 ** 15) while True: # Blink LED led.value = True time.sleep(0.2) led.value = False time.sleep(0.2) """ Test IR Transmit """ # test_pulse = pulseio.PulseOut(pwm) # remote.transmit(test_pulse, OKAY) # print("Sent Test IR Signal!", OKAY) # time.sleep(0.2)
import array import digitalio import pulseio import board import adafruit_irremote import time VOLUMEUP = bytearray(b'*L\x02\x80\xe8j') VOLUMEDOWN = bytearray(b'*L\x02\x88\xe8b') remote = adafruit_irremote.GenericTransmit((3350, 1675), (460, 1300), (460, 400), 465) left = digitalio.DigitalInOut(board.LEFT_BUTTON) right = digitalio.DigitalInOut(board.RIGHT_BUTTON) left.switch_to_input(pull=digitalio.DigitalInOut.Pull.DOWN) right.switch_to_input(pull=digitalio.DigitalInOut.Pull.DOWN) with pulseio.PWMOut(board.REMOTEOUT, frequency=38000, duty_cycle=2**15) as pwm: pulse = pulseio.PulseOut(pwm) while True: if left.value: remote.transmit(pulse, VOLUMEUP) if right.value: remote.transmit(pulse, VOLUMEDOWN)