Skip to content

Commit edcadb3

Browse files
committed
use Pin, not PWMOut, for PulseOut
1 parent 0345780 commit edcadb3

3 files changed

Lines changed: 16 additions & 76 deletions

File tree

CircuitPython_TVBGone/cpx_main/code.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import time
77

88
import board
9-
import pwmio
109
import pulseio
1110
from digitalio import DigitalInOut, Direction, Pull
11+
1212
# pylint: disable=eval-used
1313
# Switch to select 'stealth-mode'
1414
switch = DigitalInOut(board.SLIDE_SWITCH)
@@ -33,10 +33,6 @@
3333
button_b.direction = Direction.INPUT
3434
button_b.pull = Pull.DOWN
3535

36-
pwm = pwmio.PWMOut(board.REMOTEOUT, frequency=38000,
37-
duty_cycle=2 ** 15, variable_frequency=True)
38-
pulse = pulseio.PulseOut(pwm)
39-
4036
while True:
4137
# Wait for button press!
4238
while not (button_a.value or button_b.value):
@@ -54,26 +50,28 @@
5450
spkr.value = True
5551
# If this is a repeating code, extract details
5652
try:
57-
repeat = code['repeat']
58-
delay = code['repeat_delay']
53+
repeat = code["repeat"]
54+
delay = code["repeat_delay"]
5955
except KeyError: # by default, repeat once only!
6056
repeat = 1
6157
delay = 0
6258
# The table holds the on/off pairs
63-
table = code['table']
59+
table = code["table"]
6460
pulses = [] # store the pulses here
6561
# Read through each indexed element
66-
for i in code['index']:
62+
for i in code["index"]:
6763
pulses += table[i] # and add to the list of pulses
6864
pulses.pop() # remove one final 'low' pulse
6965

70-
pwm.frequency = code['freq']
71-
for i in range(repeat):
72-
pulse.send(array.array('H', pulses))
73-
time.sleep(delay)
66+
with pulseio.PulseOut(
67+
board.REMOTEOUT, frequency=code["freq"], duty_cycle=2**15
68+
) as pulse:
69+
for i in range(repeat):
70+
pulse.send(array.array("H", pulses))
71+
time.sleep(delay)
7472

7573
led.value = False
7674
spkr.value = False
77-
time.sleep(code['delay'])
75+
time.sleep(code["delay"])
7876

7977
f.close()

CircuitPython_TVBGone/gemma_main/code.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

Owl_IR_TV_Remote/code.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import array
55
import pulseio
6-
import pwmio
76
import board
87
from digitalio import DigitalInOut, Direction, Pull
98
from adafruit_debouncer import Debouncer
@@ -25,9 +24,10 @@
2524
pixel = neopixel.NeoPixel(pix, num_pixels, brightness=0.8, auto_write=False)
2625

2726
# PWM setup for IR LEDs
28-
pwm = pwmio.PWMOut(board.TX, frequency=38000, duty_cycle=2**15)
29-
remote = pulseio.PulseOut(pwm)
27+
remote = pulseio.PulseOut(board.TX, frequency=38000, duty_cycle=2**15)
3028
# power on pulse array
29+
# Prevent black from reformatting the arrays.
30+
# fmt: off
3131
power_on = array.array('H', [9027, 4490, 577, 563, 549, 1677, 579, 1674, 582, 558,
3232
554, 559, 553, 561, 551, 562, 551, 1675, 580, 1674, 572,
3333
567, 555, 1672, 573, 567, 556, 558, 554, 559, 553, 560,
@@ -43,6 +43,7 @@
4343
566, 546, 1707, 549, 1704, 551, 562, 550, 1703, 553, 1699,
4444
556, 1697, 548, 1705, 551, 1701, 554, 560, 553, 560, 552,
4545
1701, 554])
46+
# fmt: on
4647
# array of the pulses
4748
signals = [power_on, power_off]
4849
# neopixel colors

0 commit comments

Comments
 (0)