The mapper tab has a dropdown for examples, pick the Matrix example and click Load Example.
On line 2, you’ll see the
width = 8 setting, change that to 16.
Do you know if your matrix is wired zigzag, or straight across? Many matrix panels have alternating directions for how the data is wired. The example includes code to do that on line 7. If your panel is straight across, comment out that line.
Once the settings are dialed in, click Save just below the editor. Now you have a pixel map installed!
To use it, the pattern needs to implement a render2D function. There are some newer patterns on the pattern site that have 2d and 3d functions, check these out:
cube fire 3D
fast pulse 3d
sound - spectromatrix optim
There are also some originals that do the pixel mapping in the pattern (change the width setting in the pattern code and save):
matrix 2D honeycomb
matrix 2D pulse
To make a spectrum analyzer, you’ll want to translate the x coordinate to some frequency. You can do this pretty easily since the pixel map scales the coordinates to fit, so
x will be from 0.0 to 1.0. To get a frequency, you can multiply
x by the number of elements in the
frequencyData array from the sensor board, which is 32:
fx = frequencyData[x*32]
Now with a specific frequency in hand, you’ll want to draw LEDs up to some threshold based on
y. Since the frequencyData value will usually be very small, you’ll want to scale that and play around with the value until it is responsive to your audio levels. Something like this:
v = fx > y * .05 ? 1 : 0
This will set
v to 1 when it is above the threshold, and 0 otherwise.
That should get you a very basic spectrum analyzer. Beyond that, it might be interesting to slightly filter the frequencies to smooth out the response, or implement peak indicators. You might also want to borrow the automatic gain control using the PIController stuff from the other sound patterns so that it can adapt to different sound levels.
Let us know how it goes!