use Pin, not PWMOut, for PulseOut
This commit is contained in:
parent
0345780798
commit
edcadb35de
3 changed files with 16 additions and 76 deletions
|
|
@ -6,9 +6,9 @@ import array
|
|||
import time
|
||||
|
||||
import board
|
||||
import pwmio
|
||||
import pulseio
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
|
||||
# pylint: disable=eval-used
|
||||
# Switch to select 'stealth-mode'
|
||||
switch = DigitalInOut(board.SLIDE_SWITCH)
|
||||
|
|
@ -33,10 +33,6 @@ button_b = DigitalInOut(board.BUTTON_B)
|
|||
button_b.direction = Direction.INPUT
|
||||
button_b.pull = Pull.DOWN
|
||||
|
||||
pwm = pwmio.PWMOut(board.REMOTEOUT, frequency=38000,
|
||||
duty_cycle=2 ** 15, variable_frequency=True)
|
||||
pulse = pulseio.PulseOut(pwm)
|
||||
|
||||
while True:
|
||||
# Wait for button press!
|
||||
while not (button_a.value or button_b.value):
|
||||
|
|
@ -54,26 +50,28 @@ while True:
|
|||
spkr.value = True
|
||||
# If this is a repeating code, extract details
|
||||
try:
|
||||
repeat = code['repeat']
|
||||
delay = code['repeat_delay']
|
||||
repeat = code["repeat"]
|
||||
delay = code["repeat_delay"]
|
||||
except KeyError: # by default, repeat once only!
|
||||
repeat = 1
|
||||
delay = 0
|
||||
# The table holds the on/off pairs
|
||||
table = code['table']
|
||||
table = code["table"]
|
||||
pulses = [] # store the pulses here
|
||||
# Read through each indexed element
|
||||
for i in code['index']:
|
||||
for i in code["index"]:
|
||||
pulses += table[i] # and add to the list of pulses
|
||||
pulses.pop() # remove one final 'low' pulse
|
||||
|
||||
pwm.frequency = code['freq']
|
||||
for i in range(repeat):
|
||||
pulse.send(array.array('H', pulses))
|
||||
time.sleep(delay)
|
||||
with pulseio.PulseOut(
|
||||
board.REMOTEOUT, frequency=code["freq"], duty_cycle=2**15
|
||||
) as pulse:
|
||||
for i in range(repeat):
|
||||
pulse.send(array.array("H", pulses))
|
||||
time.sleep(delay)
|
||||
|
||||
led.value = False
|
||||
spkr.value = False
|
||||
time.sleep(code['delay'])
|
||||
time.sleep(code["delay"])
|
||||
|
||||
f.close()
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Gemma M0 version of TVBgone!
|
||||
import array
|
||||
import time
|
||||
|
||||
import adafruit_dotstar
|
||||
import board
|
||||
import pwmio
|
||||
import pulseio
|
||||
from digitalio import DigitalInOut, Direction
|
||||
|
||||
# pylint: disable=eval-used
|
||||
|
||||
pixel = adafruit_dotstar.DotStar(
|
||||
board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
|
||||
pixel.fill((0, 0, 0))
|
||||
|
||||
# Button to see output debug
|
||||
led = DigitalInOut(board.D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
pwm = pwmio.PWMOut(board.A2, frequency=38000,
|
||||
duty_cycle=2 ** 15, variable_frequency=True)
|
||||
pulse = pulseio.PulseOut(pwm)
|
||||
|
||||
time.sleep(0.5) # Give a half second before starting
|
||||
|
||||
# gooooo!
|
||||
f = open("/codes.txt", "r")
|
||||
for line in f:
|
||||
code = eval(line)
|
||||
print(code)
|
||||
pwm.frequency = code['freq']
|
||||
led.value = True
|
||||
# If this is a repeating code, extract details
|
||||
try:
|
||||
repeat = code['repeat']
|
||||
delay = code['repeat_delay']
|
||||
except KeyError: # by default, repeat once only!
|
||||
repeat = 1
|
||||
delay = 0
|
||||
# The table holds the on/off pairs
|
||||
table = code['table']
|
||||
pulses = [] # store the pulses here
|
||||
# Read through each indexed element
|
||||
for i in code['index']:
|
||||
pulses += table[i] # and add to the list of pulses
|
||||
pulses.pop() # remove one final 'low' pulse
|
||||
|
||||
for i in range(repeat):
|
||||
pulse.send(array.array('H', pulses))
|
||||
time.sleep(delay)
|
||||
led.value = False
|
||||
time.sleep(code['delay'])
|
||||
|
||||
f.close()
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
import array
|
||||
import pulseio
|
||||
import pwmio
|
||||
import board
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
from adafruit_debouncer import Debouncer
|
||||
|
|
@ -25,9 +24,10 @@ num_pixels = 1
|
|||
pixel = neopixel.NeoPixel(pix, num_pixels, brightness=0.8, auto_write=False)
|
||||
|
||||
# PWM setup for IR LEDs
|
||||
pwm = pwmio.PWMOut(board.TX, frequency=38000, duty_cycle=2**15)
|
||||
remote = pulseio.PulseOut(pwm)
|
||||
remote = pulseio.PulseOut(board.TX, frequency=38000, duty_cycle=2**15)
|
||||
# power on pulse array
|
||||
# Prevent black from reformatting the arrays.
|
||||
# fmt: off
|
||||
power_on = array.array('H', [9027, 4490, 577, 563, 549, 1677, 579, 1674, 582, 558,
|
||||
554, 559, 553, 561, 551, 562, 551, 1675, 580, 1674, 572,
|
||||
567, 555, 1672, 573, 567, 556, 558, 554, 559, 553, 560,
|
||||
|
|
@ -43,6 +43,7 @@ power_off = array.array('H', [9028, 4491, 576, 563, 549, 1678, 578, 1701, 554, 5
|
|||
566, 546, 1707, 549, 1704, 551, 562, 550, 1703, 553, 1699,
|
||||
556, 1697, 548, 1705, 551, 1701, 554, 560, 553, 560, 552,
|
||||
1701, 554])
|
||||
# fmt: on
|
||||
# array of the pulses
|
||||
signals = [power_on, power_off]
|
||||
# neopixel colors
|
||||
|
|
|
|||
Loading…
Reference in a new issue