I am trying to get my CPB to send out the same irremote signal through two different pins. It does show on the pinout that both TX and A6 are PWM out. TX is working fine, but A6/RX is not firing correctly. It only does a brief bit of the pulse out and stops short. I have included the code below. The plan is to attached the CPB to a glove, and have an IR LED on the back of the hand and one on the palm, so the remote signal can be sent no matter which position the hand is in.
Code: Select all
import time
import pulseio
import busio
import board
import adafruit_irremote
from adafruit_circuitplayground import cp
# Create a 'PulseOut' to send infrared signals on the IR transmitter @ 38KHz
pulseout = pulseio.PulseOut(board.TX, frequency=38000, duty_cycle=2**15)
pulseout2 = pulseio.PulseOut(board.RX, 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=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0
)
encoder2 = adafruit_irremote.GenericTransmit(
header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0
)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (255, 255, 255)
OFF = (0, 0, 0)
heals = (255, 0, 93, 162)
cp.pixels.brightness = 0.3
def color_chase(color, wait):
for i in range(10):
cp.pixels[i] = color
time.sleep(wait)
time.sleep(0.02)
def flash_hit(color):
color_chase(RED, .02)
color_chase(OFF, .02)
color_chase(color, .02)
cp.play_file("examples_dip.wav")
cp.pixels.fill(BLUE)
while True:
x, y, z = cp.acceleration
if cp.shake(shake_threshold=11):
if z < -5.0 and (y < 5.0 or y > -5.0):
encoder.transmit(pulseout, [255, 0, 93, 162])
encoder2.transmit(pulseout2, [255, 0, 93, 162])
flash_hit(GREEN)
print(x, y, z)
print(encoder.transmit(pulseout2, [255, 0, 93, 162]))
time.sleep(0.2)
elif y > 5.0: # palm facing away
if x < -5.0: # tipped counterclockwise
encoder.transmit(pulseout, [50, 2, 255, 50])
encoder2.transmit(pulseout2, [50, 2, 255, 50])
flash_hit(YELLOW)
print(x, y, z)
print(pulseout2)
time.sleep(0.2)
elif x > 5.0: # tipped clockwise
encoder.transmit(pulseout, [255, 0, 93, 50])
encoder2.transmit(pulseout2, [255, 0, 93, 50])
flash_hit(WHITE)
print(x, y, z)
print(pulseout2)
time.sleep(0.2)
else: # straight up
encoder.transmit(pulseout, [200, 0, 93, 50])
encoder2.transmit(pulseout2, [200, 0, 93, 50])
flash_hit(BLUE)
print(x, y, z)
print(pulseout2)
time.sleep(0.2)
elif y < -5.0: # palm facing toward (hand down)
encoder.transmit(pulseout, [200, 0, 93, 50])
encoder2.transmit(pulseout2, [200, 0, 93, 50])
flash_hit(PURPLE)
print(x, y, z)
print(pulseout2)
time.sleep(0.2)