WS8212B Bar Graphs with NeoMatrix

Hello,

I’m working on a project that will simulate the output of a frequency analyser - it’s basically a 20 pixel high four pixel wide grid of WS8212B RGB tape. - Each column ‘bounces’ up and down, red at the top, green at the bottom sort of thing…

After a few failed attempts at getting them to run concurrently, I found this Neomatrix EQ Bar Library which looked like it would very easily do exactly what I needed it to.

At first it wasn’t working - I narrowed it down to the colorwheel code in the library, and worked around it by building my own colours in. After this I had one column of pixels doing exactly as I needed it to.

The documentation on Github explains how to then duplicate this over multiple columns - and this is where I’m completely stuck. I’ve tried both of the listed methods (repeating code and for loops) - as soon as you add another column the code compiles but does absolutely nothing.

I put a number of serial prints in to see where the code was getting stuck, and it wasn’t running at all, sometimes with gibberish being sent to the serial monitor.

#include "NeoMatrixEqBar.h"

//matrix constants
const int MATRIX_PIN = 6;
const int MATRIX_WIDTH = 4;
const int MATRIX_HEIGHT = 20;
const int MATRIX_PIXEL_TYPE = NEO_RGB + NEO_KHZ800;
const int MATRIX_BRIGHTNESS = 10;

//animation speed
//lower values means FASTER!
const int speed = 40;

//matrix setup
const int MATRIX_OPTIONS =
    NEO_MATRIX_TOP +
    NEO_MATRIX_LEFT +
    NEO_MATRIX_COLUMNS +
    NEO_MATRIX_PROGRESSIVE;

//declare the matrix
Adafruit_NeoMatrix matrix =
    Adafruit_NeoMatrix(
        MATRIX_WIDTH,
        MATRIX_HEIGHT,
        MATRIX_PIN,
        MATRIX_OPTIONS,
        MATRIX_PIXEL_TYPE);

/* build a Neo Matrix EQ bar
    &matrix - a pointer to the matrix.
    0 - which column
    0 - starting height
    MATRIX_HEIGHT - the EQ bar's max height;
*/

NeoMatrixEqBar eqBars[4];

void setup()
{
    Serial.begin(9600);
    Serial.println("start");

    //init the matrix
    matrix.begin();
    matrix.setBrightness(MATRIX_BRIGHTNESS);
    matrix.clear();
    matrix.show();


//build the EQ bars, one for each column of our matrix
  for (int i = 0; i < MATRIX_WIDTH; i++) {
    /* build a Neo Matrix EQ bar
      &matrix - a pointer to the matrix.
      0 - which column
      0 - starting height
      MATRIX_HEIGHT - the EQ bar's max height;
    */
    NeoMatrixEqBar eqBar = NeoMatrixEqBar(&matrix, i, 0, MATRIX_HEIGHT);
    //init the eqBar
    eqBar.begin();
    eqBar.randomizeSpeed(true);

    //add to the array
    eqBars[i] = eqBar;
  }
    
}

void loop()
{
     //tick the EQ bars to update them
  for (int i = 0; i < MATRIX_WIDTH; i++) {
    eqBars[i].tick();
  }

    matrix.show();
    delay(speed);
    matrix.clear();
}

Please can anyone shed any light on why this is happening? I know the loops are working, as reducing ‘MATRIX_WIDTH’ to 1 has it working as before…

Also not sure if it’s relevant but for some reason it’s upside down… setting MATRIX_TOP fixes this, even though it’s technically incorrect.

Thanks in advance for any advice :slight_smile: