RGB 64*32 matrix maze, check if LED on


I’m trying to make a sort of maze on the 64*32 matrix.
Therefore I want to check if a LED is black or has any other color than black. If the color of a certain LED at (x, y) is black, the space is free to move to, but if the LED has a color, a sort of collision needs to happen saying you can’t move there.
(Moving a single white LED around using a joystick)

Code is included.
Any help is appreciated!

Matrix_with_joystick.ino (2.78 KB)

Doesn’t your library offer methods to retrieve a pixel state, like getPixel()?

How come you don't know a state that you set yourself?

I can't find anything related to retrieving the color of a certain LED.
The only thing I could possibly imagine to be related to that is the following:

        uint8_t   *ptr  = &buffer[(x / 8 ) + y * ((WIDTH + 7) / 8 )];
#ifdef __AVR__
        if(color) *ptr |= pgm_read_byte(&GFXsetBit[x & 7]);
        else      *ptr &= pgm_read_byte(&GFXclrBit[x & 7]);
        if(color) *ptr |=   0x80 >> (x & 7);
        else      *ptr &= ~(0x80 >> (x & 7));

I don't know what this says, though. I'm still kinda new to library language.

How come you don't know a state that you set yourself?

Well, using a font to type letters, you don't trigger each LED manually so the code itself doesn't know exactly which LEDs are on.

Do you have the RAM to create a 256 byte array?

You have 64 x 32 LEDs. Since 32 is the number of bits in 4 bytes you could represent the state of each LED with a single bit (0=black, 1=not black.)

xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 31
xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 63
xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 95
xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 127
xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 159

where each ‘x’ represents an LED state.

You could then set/clr a bit with:

void SetLED( int nLED, bool State )
    byte idx;
    if( nLED > 2047 )

    idx = nLED>>3;

    if( bState == true )
        LEDArray[idx] |= 0x80 >> (nLED - (idx<<3));
        LEDArray[idx] &= ~(0x80 >> (nLED - (idx<<3)));


and check its state with:

bool CheckLED( int nLED )
    byte idx;
    if( nLED > 2048 )
        return false;
    idx = nLED>>3;
return( LEDArray[idx] & (0x80 >> (nLED - (idx<<3)))?true:false);