From 6e7de35e6f192fb245c9376cf3ae486cb1783fce Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 24 Jul 2018 13:52:19 -0400 Subject: [PATCH 1/4] Adding transmit example. --- examples/ir_transmit.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/ir_transmit.py diff --git a/examples/ir_transmit.py b/examples/ir_transmit.py new file mode 100644 index 0000000..c0450c8 --- /dev/null +++ b/examples/ir_transmit.py @@ -0,0 +1,28 @@ +"""IR transmit example using Circuit Playground Express""" +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 +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!") + 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!") + cpx.red_led = True + encoder.transmit(pulseout, [255, 2, 191, 64]) + cpx.red_led = False + time.sleep(0.2) From 6e219542c2acf208cf6de1dbb704d4a768ca8a84 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 24 Jul 2018 13:58:55 -0400 Subject: [PATCH 2/4] Simplified. --- examples/ir_transmit.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/ir_transmit.py b/examples/ir_transmit.py index c0450c8..22dab09 100644 --- a/examples/ir_transmit.py +++ b/examples/ir_transmit.py @@ -1,9 +1,14 @@ """IR transmit example using Circuit Playground Express""" import time -from adafruit_circuitplayground.express import cpx import adafruit_irremote import pulseio import board +import digitalio + +# Create a button object to trigger IR transmit +button = digitalio.DigitalInOut(board.D4) +button.direction = digitalio.Direction.INPUT +button.pull = digitalio.Pull.DOWN # 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) @@ -13,16 +18,6 @@ zero=[550, 1700], trail=0) while True: - if cpx.button_a: - print("Button A pressed!") - cpx.red_led = True + if button.value: 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!") - cpx.red_led = True - encoder.transmit(pulseout, [255, 2, 191, 64]) - cpx.red_led = False time.sleep(0.2) From 6d0ee99578ade8cec6610acc8791e18a98db7ce3 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 24 Jul 2018 15:46:01 -0400 Subject: [PATCH 3/4] Added print to send --- examples/ir_transmit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ir_transmit.py b/examples/ir_transmit.py index 22dab09..80e090d 100644 --- a/examples/ir_transmit.py +++ b/examples/ir_transmit.py @@ -8,6 +8,7 @@ # Create a button object to trigger IR transmit button = digitalio.DigitalInOut(board.D4) button.direction = digitalio.Direction.INPUT +# This is for CPX. For an external button button.pull = digitalio.Pull.DOWN # Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz @@ -19,5 +20,6 @@ while True: if button.value: + print("IR signal sent!") encoder.transmit(pulseout, [255, 2, 255, 0]) time.sleep(0.2) From ba9572f7fe6aea815407416824a1e3c8d1c2daa1 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 24 Jul 2018 16:07:31 -0400 Subject: [PATCH 4/4] Removed comment --- examples/ir_transmit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/ir_transmit.py b/examples/ir_transmit.py index 80e090d..5827bc8 100644 --- a/examples/ir_transmit.py +++ b/examples/ir_transmit.py @@ -8,7 +8,6 @@ # Create a button object to trigger IR transmit button = digitalio.DigitalInOut(board.D4) button.direction = digitalio.Direction.INPUT -# This is for CPX. For an external button button.pull = digitalio.Pull.DOWN # Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz