Closed rhubarbdog closed 2 years ago
From the code above, it looks like the music tune is playing in the background but finishing (via sleep(1000*1)) before the LEDs are written to. So there shouldn't be any interference between the music and LEDs. What happens if the music plays in the foreground, does it work then?
i've tried the following 1) playing the music in the foreground 2) swapping the order of events for the above code. so neopixel, sleep, music ,sleep 3) swapping the order of events for playing music in the foreground
All 4 cases play the music once then stop playing the music for most loops playing 1:6 maybe. but not every 6 loops.
regarding your comment "music tune is playing in the background but finishing (via sleep(10001))" I added `sleep(10001)` to try and cast some light on the issue, without it like the above cases the music plays once then stops only playing in some subsequent loops
Out of curiosity, how are you powering it? Perhaps it's restarting because of the voltage sag due to the neopixels lighting up? Do you get anything displayed on the serial?
I'm powering it of 3 * 1.5volt alkaline batteries. Which are new, but not heavy duty type like duracell. The microbit is powered by theses via the GPIO connector. I've tried running the code from the initial post with a usb power lead in to keep the microbit alive the music still stops after 1 play and then only plays on some loops, it appears to be more like 1:11.
You ask "Do you get anything displayed on the serial?", how would i test this? i have just tried adding a couple of print statements and checked they were working using a REPL session with screen
I've tried the following 1) using a different speaker, some genuine neopixel (ws2812 addressable LEDs) and a different microbit i ran the code in my original post. I have used a level shifter between the microbit and neopixels which have their own 5volt supply. Music playback is still defective i.e. plays the first time, then 1:6 -> 1:11 playbacks:loops 2) to isolate this further i produced these blocks and music plays correctly every loop
I can confirm this issue. The problem is that when there are lots of neopixels the interrupts are disabled for a long time, and the PWM (which drives the music) stops functioning. This is because it is software based, misses an interrupt, and the next time it gets a chance to service an interrupt and update the counter for the time of the next interrupt, that next interrupt already passed. In that case it has to wait for the counter to wrap around before it starts functioning again. Since the counter is 24 bits and running at 1MHz, it takes about 16seconds to start working again.
Just so you're aware. I was able to reproduce the bug with only 8 neopixels
I would like to get going with the joypad i bought i'm thinking about writing an article for it for micro:mag but need a .hex file that it would work with. has the relevant pull request been joined to a repository so i can test the fix and hopefully write a good game to show off what a cool daughter board this is for the microbit
This was fixed in commit 3b55d0d9111875a5da35c199927876bf320ee5f8. I tested that it indeed fixes the original code posted at the top of this issue.
i've bought this joypad (kitronik game zip). It has a little speaker and an array of "zip LEDs" (neopixel compatible addressable LEDs) when i run the following program the music plays once at the start and then about every 5 loops randomly.
i've tried it on the 'old' web editor and the music plays, but there are issues with neopixel and all LEDs are lit bright white rather than 1 yellow LED.