#Yah, still not playing

1 messages · Page 1 of 1 (latest)

high tartan
#
import time
import board
import neopixel
import audiocore

from adafruit_debouncer import Debouncer
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.helper import PixelSubset

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        pass  # not always supported by every board!

HUM_LOOP = "Afterlife_hum_loop_01.wav"  # Change to the name of your wav file!
START = "Afterlife_pack_startup.wav"

pin = digitalio.DigitalInOut(board.D9)
pin.direction = digitalio.Direction.INPUT
pin.pull = digitalio.Pull.UP
switch = Debouncer(pin)
pin2 = digitalio.DigitalInOut(board.D5)
pin2.direction = digitalio.Direction.INPUT
pin2.pull = digitalio.Pull.UP
switch2 = Debouncer(pin2)
pin3 = digitalio.DigitalInOut(board.D12)
pin3.direction = digitalio.Direction.INPUT
pin3.pull = digitalio.Pull.UP
switch3 = Debouncer(pin3)


with AudioOut(board.A0) as audio:  # Speaker connector
    start = open(START, "rb")
    wave2 = audiocore.WaveFile(start)

    audio.play(wave2)
    
while True:

    changeon = False
    change2on = False
    changeoff = False
    change2off = False
    change3on = False
    change3off = False

    switch.update()
    switch2.update()
    switch3.update()

    if switch.fell:
        changeon = True
    if switch.rose:
        changeoff = True
    if switch2.fell:
        change2on = True
    if switch2.rose:
        change2off = True
    if switch3.fell:
        change3on = True
    if switch3.rose:
        change3off = True
    if changeon:
        print("not pressed 1")
    if changeoff:
        print("pressed 1")
    if change2on:
        print("not pressed 2")
    if change2off:
        print("pressed 2")
    if change3on:
        print("not pressed 3")
    if change3off:
        print("pressed 3")
    time.sleep(0.5)
modern nacelle
#

You need to remove it from the with block

#

Otherwise it tears it down on the next line

high tartan
#

Oooh, ok

#

moment

#

so like

#
    start = open(START, "rb")
    wave2 = audiocore.WaveFile(start)
audio.play(wave2)```
modern nacelle
#

Did that come from an example?

high tartan
#

Yep

#

worked on other code, not sure why it's not working now

modern nacelle
#

Typically after with something after you exit the with it's all torn down

high tartan
#

ok, moment...

modern nacelle
#

But also like I said yesterday, I haven't messed with audio on controllers

high tartan
#

oh no worries!

modern nacelle
#

Where's the example?

#

And what happens if you do:

audio = AudioOut(board.A0)
start = open(START, "rb")
wave2 = audiocore.WaveFile(start)
audio.play(wave2)
high tartan
#

moent, looking for it, it was on the Adafruit page

#

moment

#

nothing

#

dfasng it, can't find the project

#

i have my old code, that does put out sound though

modern nacelle
#

Still?

high tartan
#

yah, i saved it

#

moent

modern nacelle
#

Thought maybe you had a loose wire

high tartan
#

moment, something is going werid with my PC

#

hm, USB is havbeing some problems, but anywho! fixed that at least

#
import time
import board
import neopixel
import audiocore


from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.helper import PixelSubset

button = digitalio.DigitalInOut(board.D11)
button.switch_to_input(digitalio.Pull.UP)  # pull up: HIGH / True is unpressed

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        pass  # not always supported by every board!
HUM_LOOP = "Afterlife_hum_loop_01.wav"  # Change to the name of your wav file!
START = "Afterlife_pack_startup.wav"

enable = digitalio.DigitalInOut(board.D10)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True

NUM_PIXELS = 60
BAR_NUM = 16
NEOPIXEL_PIN = board.D5
BAR = board.D12
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
)

cometBlue = Comet(
    strip,
    speed=0.01,
    color=(255, 0, 0),
    tail_length=5,
    ring=True,
    bounce=False,
)

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:

    with AudioOut(board.A0) as audio:  # Speaker connector
        start = open(START, "rb")
        wave2 = audiocore.WaveFile(start)

        audio.play(wave2)

        while audio.playing:
            cometBlue.animate()
            ledfill.update()
            pass

    with AudioOut(board.A0) as audio:  # Speaker connector
        hum_loop = open(HUM_LOOP, "rb")
        wave1 = audiocore.WaveFile(hum_loop)

        audio.play(wave1, loop=True)

        while audio.playing:
            cometBlue.animate()
            ledfill.update()
            if button.value is False:  # LOW / False is pressed
                print("button press!")
                time.sleep(0.2)
            pass
#

That will play the startup sound, and the hum on loop

modern nacelle
#

Hmmm

high tartan
#

heh, I should've mentioned, I have a history of making electronics break in new, exciteing, and unusual ways

modern nacelle
#

What if you move the audio into the loop? You may need to ask this in the main thread. I know audio works outside the main handler so it can play and not stop when you do things

high tartan
#

I'll check