0

CPX/Crickit Sound & Lights
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CPX/Crickit Sound & Lights

by htmagic on Mon Apr 26, 2021 11:08 am

Hello,

I have a Circuit Playground Express (CPX)/Crickit board where I want to run a .wav file, light a 8 pixel LED strip, then continue playing the first .wav file, followed by a second .wav file.
Is that even possible? I want to play the first .wav file which is about 10 sec long for 5 seconds, then turn on the LED strip for 5 seconds and continue the first .wav file, followed by a second .wav file.

I had someone help me with coding but the LEDs would not light.
I sent a copy of the code. I cut out the other buttons (1,2,3) as they are not pertinent to this and those routines work fine (no LEDs).

So can a CPX/Crickit even do this? Or will I have to break the first .wav file into 2 .wav files and play the first half, followed by the LEDs lite for a few seconds, followed by the second half of the first .wav file, followed by the last .wav file?

I attached the code as a ,txt file for your viewing please.
Any ideas, comments, tips, would be appreciated.
Thank you in advance for your review and help with this issue.
May the FORCE be with you and have a magical day!

MagicBill
Attachments
mod_code.txt
(1.83 KiB) Downloaded 4 times

htmagic
 
Posts: 77
Joined: Tue Dec 03, 2013 12:18 am

Re: CPX/Crickit Sound & Lights

by mikeysklar on Tue Apr 27, 2021 8:23 pm

You should be able to background the WAV file. Were you using CircuitPython or Arduino?

Here is an example that backgrounds the WAV file so you could be running LEDs while the audio is going.

Code: Select all | TOGGLE FULL SIZE
import board
import digitalio

try:
    from audiocore import WaveFile
except ImportError:
    from audioio import WaveFile

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

# Enable the speaker
spkrenable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = digitalio.Direction.OUTPUT
spkrenable.value = True

# Make the 2 input buttons
buttonA = digitalio.DigitalInOut(board.BUTTON_A)
buttonA.direction = digitalio.Direction.INPUT
buttonA.pull = digitalio.Pull.DOWN

buttonB = digitalio.DigitalInOut(board.BUTTON_B)
buttonB.direction = digitalio.Direction.INPUT
buttonB.pull = digitalio.Pull.DOWN

# The two files assigned to buttons A & B
audiofiles = ["rimshot.wav", "laugh.wav"]


def play_file(filename):
    print("Playing file: " + filename)
    wave_file = open(filename, "rb")
    with WaveFile(wave_file) as wave:
        with AudioOut(board.SPEAKER) as audio:
            audio.play(wave)
            while audio.playing:
                pass
    print("Finished")


while True:
    if buttonA.value:
        play_file(audiofiles[0])
    if buttonB.value:
        play_file(audiofiles[1])



https://learn.adafruit.com/adafruit-cir ... -audio-out

mikeysklar
 
Posts: 4508
Joined: Mon Aug 01, 2016 8:10 pm

Re: CPX/Crickit Sound & Lights

by htmagic on Wed Apr 28, 2021 8:29 am

mikeysklar,

Thank you so much for your review and response.
I am using CircuitPython and unfortunately, I tried to upgrade CircuitPython last night to the board and broke things.
I can't get anything to work right now.
I will try to play around with this tonight after work, after I reinstall CircuitPython.

Thanks again for your assistance.
May the FORCE be with you and have a magical day!

MagicBill

htmagic
 
Posts: 77
Joined: Tue Dec 03, 2013 12:18 am

Re: CPX/Crickit Sound & Lights

by htmagic on Tue May 04, 2021 9:27 am

Here is a follow up post on this issue.

After looking through the Adafruit pages and going back to the LED strip I purchased, I went here: https://www.adafruit.com/product/1426
If you look at the last photo, it shows the backside of the board.
And if you look carefully, you can see the GND (ground, or negative), Dout (on left) Din (on right), 4-7 VDC, and GND pins.

So the D line is the signal that goes to the Crickit board on the CPX/Crickit.
And the proper terminal to use is Din!!!
I HAD IT BACKWARDS WITH Dout AND IT WILL NOT WORK RIGHT!!!
So the moral of the story is use Din for the signal line to the LED strip and to the signal pin on the terminal strip on the Crickit board.
If you use Dout, it will not work properly.

So as I understand it, the signal comes into the LED strip through Din. If you want to daisy chain more strips, Dout goes to Din on another strip and so on.

So if you're having trouble with neopixels, make sure you connected the right terminal.
This has been an education, and I appreciate the support through this forum.
And hopefully I've made someone's day and they can get their project working correctly.
May the 4th be with you and have a magical day!

MagicBill

htmagic
 
Posts: 77
Joined: Tue Dec 03, 2013 12:18 am

Re: CPX/Crickit Sound & Lights

by mikeysklar on Tue May 04, 2021 7:41 pm

MagicBill,

Good job resolving your issue with DIN / DOUT being mixed up. May the 4th be with you as well.

mikeysklar
 
Posts: 4508
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.