Getting back into the hobby...got some more learning to do! Starting back with RGB
eagletalontim
Posts: 1,399
Been quite some time since I have posted here and now I am quite rusty! Not sure what all has changed, but I had some old PCB's with the Prop soldered to them and started dabbling with SPIN code again. Never could grasp Assembly
A worker of mine is interested in doing an RGB or ARGB sound activated controller. After doing a bit of research, I have located an interesting IC...the MSGEQ7 which apparently is an amazing IC and can easily split the spectrum of an audio signal to 7 different spectrums. I really don't need all 7, but hey, if they are offered, why not use them. We would like to have the RGB change color based on the spectrum, not volume.
https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf
Problem I have is properly communicating with the MSGEQ7 from the Prop. I really suck at fully understanding datasheets and putting the information in them to proper use. I can see there are 2 pins that are Reset and Strobe which I believe are the signal needed from the Prop to get data out from the MSGEQ7.
So from what I gather is I need to do something like? :
So none of this code is tested at all since I have not bought the MSGEQ7 just yet. This is off the top of my head :P Maybe there is a better option out there for what I am trying to do I seen another project using the same IC, but there is no code to go by.
A worker of mine is interested in doing an RGB or ARGB sound activated controller. After doing a bit of research, I have located an interesting IC...the MSGEQ7 which apparently is an amazing IC and can easily split the spectrum of an audio signal to 7 different spectrums. I really don't need all 7, but hey, if they are offered, why not use them. We would like to have the RGB change color based on the spectrum, not volume.
https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf
Problem I have is properly communicating with the MSGEQ7 from the Prop. I really suck at fully understanding datasheets and putting the information in them to proper use. I can see there are 2 pins that are Reset and Strobe which I believe are the signal needed from the Prop to get data out from the MSGEQ7.
So from what I gather is I need to do something like? :
CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 OBJ Pst : "Parallax Serial Terminal" ' to be used for testing adc : "adc0831_fast" VAR LONG adcArray[6] ' Array to hold spectrum data from ADC BYTE i PUB main dira[reset_pin]~~ ' set to output dira[strobe_pin]~~ ' set to output outa[reset_pin] := 0 ' ensure pin is off outa[strobe_pin] := 0 ' ensure pin is off adc.start(cs, clk, data, sample_rate, @adcValue) pause(10) ' Let ADC initialize ' initialize MSGEQ7 outa[reset_pin] := 1 outa[strobe_pin] := 1 pause(2) outa[strobe_pin] := 0 pause(2) outa[reset_pin] := 0 i := 0 repeat outa[strobe_pin] := 1 pause(2) outa[strobe_pin] := 0 pause(2) ' allow time for ADC to update? adcArray[i] := adcValue pause(2) i++ if i == 7 ' array 0 to 6 for 7 spectrum data i := 0
So none of this code is tested at all since I have not bought the MSGEQ7 just yet. This is off the top of my head :P Maybe there is a better option out there for what I am trying to do I seen another project using the same IC, but there is no code to go by.
Comments
This code has not been tested either, but should represent the idea. If the "peak" is in the low range, Red will light up more intense than the rest of the ranges.
My guess is that the average peak value for each of the 7 bands will vary quite a bit, so getting a nice display may not be so easy, but since it can be done with code instead of hardware you can do a lot of experimenting. Using an array of 2811/2812 led strips with the right software would make for an awesome display. Imagine using some of the bands for color and one or two for shapes or led addressing on an xy array of leds.
Thanks to JonnyMac's code in the obex, I was able to get the strip working well with 150 LED's, but if I stretch out further, my array shift slows everything way down. The array shift is to give the appearance of the LED's traveling down to the end.
Here is the bit of code that is slowing everything down...
Is it possible to speed this up? I could not figure how to simply shift each value in an array up one and the last one "fall off"
pixbuf1[0] is updated from the calculated value of the spectrum from the MSGEQ7 which is done in the "Main" loop.
If the strip is 150 LED's long, it is quick and displays correctly even if I add a 25ms delay in the "time.pause". If I change STRIP_LEN to 600 LED's, the display of the LED's "running" down the strip slows WAY down. This leads me to believe the first part that shifts each index value up to the next index in pixbuf1 is what slows this down quite a bit.
I was thinking I would probably need to make another COG run that will just update the array, but that seems like a waste of a cog if there is another way to do this.
This is the code I used to test.
The output is:
and handle wrapping, but the cost of "shifting" goes away.
https://youtu.be/16sXoIh-F2Q