#Hey everyone, I'm so dang close to
1 messages · Page 1 of 1 (latest)
Do you have code somewhere? On a high level you have a state machine going. And guessing something is initializing early and possibly something else is blocking
oh dangf
I thought I put the code in
moment, sorry
import time
import board
import neopixel
# import audiocore
from audiocore import WaveFile
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.solid import Solid
# from adafruit_led_animation.helper import PixelSubset
switch1 = digitalio.DigitalInOut(board.D11)
switch1.switch_to_input(digitalio.Pull.UP) # pull up: HIGH / True is unpressed
switch2 = digitalio.DigitalInOut(board.D13)
switch2.switch_to_input(digitalio.Pull.UP)
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
startfile = open("Afterlife_pack_startup.wav", "rb")
humloop = open("Afterlife_hum_loop_01.wav", "rb")
wandon = open("Afterlife_thrower.wav", "rb")
HUM_LOOP = WaveFile(humloop) # Change to the name of your wav file!
START = WaveFile(startfile)
WAND_START = WaveFile(wandon)
audio = AudioOut(board.A0)
enable = digitalio.DigitalInOut(board.D10)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True
NUM_PIXELS = 60
BAR_NUM = 16
WAND_NUM = 2
NEOPIXEL_PIN = board.D5
BAR = board.D12
WAND_PIN = board.D9
POWER_PIN = board.D10
ONSWITCH_PIN = board.A1
strip = neopixel.NeoPixel(
NEOPIXEL_PIN, NUM_PIXELS, brightness=1, auto_write=False, pixel_order=neopixel.GRBW
)
strip2 = neopixel.NeoPixel(
BAR,
BAR_NUM,
brightness=1.0,
auto_write=False
)
strip3 = neopixel.NeoPixel(
WAND_PIN,
WAND_NUM,
brightness=1.0,
auto_write=False,
pixel_order=neopixel.GRBW
)
cometBlue = Comet(
strip,
speed=0.01,
color=(255, 0, 0),
tail_length=5,
ring=True,
bounce=False,
)
wandLight = Solid(
strip3,
color=(255, 255, 0, 100),
)
wandoff = Solid(
strip3,
color=(0, 0, 0, 0),
)
class LEDFill:
def __init__(self, hue, timeinc):
self.hue = hue # what color we are
self.timeinc = timeinc
self.pos = 0 # where on the ring we are
self.last_update = 0 # when we last updated
def update(self):
if time.monotonic() - self.last_update > self.timeinc:
self.last_update = time.monotonic()
strip2[self.pos] = self.hue
self.pos += 1
if self.pos == len(strip2):
self.pos = 0
strip2.fill(0)
strip2.show()
ledfill = LEDFill(0x0000FF, 0.03)
last_print = 0
while True:
if switch1.value:
cometBlue.animate()
ledfill.update()
wandoff.animate()
audio.play(START)
pass
else:
if switch2.value:
cometBlue.animate()
ledfill.update()
wandLight.animate()
pass
else:
cometBlue.animate()
ledfill.update()
wandoff.animate()
audio.play(HUM_LOOP)
pass
Sorry bout that, heh, must've sleected the wrong thing, been getting fustrated
I'm not seeing a button. Is it not there yet?
Also when you power it on (if the switches are off) it's going to land in that second else.
Ahh, the button's not there yet, sorry
sorry, was afk
Ok, so how should I chain these together so it works in...squence?
So I would probably do something more like:
if sw1 or sw2:
# do light things
elif sw1:
# do sw1 specific thing
elif sw2:
# do sw2 specific thing
else:
# stop everything
kk, gimme a sec, I'll put that in
I might also recommend looking at the de-bounce library: https://learn.adafruit.com/debouncer-library-python-circuitpython-buttons-sensors
This way you can start things when the button/switch changes, vs constantly
I don't use audio, so not sure what happens if you keep calling play
Oh don't apologize, were all learning
Hm..no, didn't work, light now is not going on...
moment
Yah, something messing up with sound. Let me comment out the sound plays, and see if i can get everything else working
I often just use print statements. Easy to see what changes when all I need to look at is the terminal
After that's working, start adding lights, etc
Yah, true
End of my day. Will check in tomorrow and see if I can help anymore