How would I go about creating a display buffer for an LED matrix controlled by an arduino

80 Views Asked by At

I recently undertook a small project which constists of creating a small video game console using an arduino, some joysticks, and a 32x8 pixel LED matrix. This matrix is actually 4 sub-matrices, which made the whole operation a lot harder, but it is working. There is only one slight issue, and that's that I'm drawing the pixels one by one, meaning there is a lot of flashing. I'm using the LedControl library and know there is someway to write the pixels to a char array buffer for each display and somehow use setRow to display them in a display function, but I have no idea how to even start. Sort of begginer level at c++ and arduino, so sorry if this question seems obvious.

I'm basing all my code off of Sebastian Lague's monster console project in case it helps.

I already tried copying some of the display code and trying to rearrange it for my displays, but I haven't been able to make it work. The 4 matrices are weirdly arranged so that display 0 is right-most and 3 is left-most, but display = 0, x = 0, y = 0 will set the top-left pixel in the right-most display

My current code:

    void setPixel() {
        int virtualMatrixIndex = (int)(x / (m_totalWidth / m_displayCount));
        int realMatrixIndex = flipMatrixIndex(virtualMatrixIndex, m_displayCount);

        // Calculate the x-coordinate relative to the matrix
        int xWithinMatrix = x % (m_totalWidth / m_displayCount);

        lc.setLed(realMatrixIndex, y, xWithinMatrix, state);
    }

EDIT: The flipMatrix function just accounts for the weird arrangement, by transforming matrix 0 into 3 and etc...

0

There are 0 best solutions below