Skip to content

Commit 0c89a08

Browse files
authored
Merge pull request #14 from kattni/add-tx-example
Add tx example
2 parents d4ff748 + ba9572f commit 0c89a08

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/ir_transmit.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""IR transmit example using Circuit Playground Express"""
2+
import time
3+
import adafruit_irremote
4+
import pulseio
5+
import board
6+
import digitalio
7+
8+
# Create a button object to trigger IR transmit
9+
button = digitalio.DigitalInOut(board.D4)
10+
button.direction = digitalio.Direction.INPUT
11+
button.pull = digitalio.Pull.DOWN
12+
13+
# Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz
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 button.value:
22+
print("IR signal sent!")
23+
encoder.transmit(pulseout, [255, 2, 255, 0])
24+
time.sleep(0.2)

0 commit comments

Comments
 (0)