Problems retrieving the index of an array from another array


I’m trying to get the index of an array from another array to get a tilemap system working.

One array stores the index numbers of the tiles on my map, the other array stores pointers to the bitmaps.

I can’t seem to get the array with the index numbers to return the correct index numbers! I can tell as it currently returns garbage to the screen when I try and reference it. If I reference the pointed tilemaps directly, they work perfectly.

The array is called map1 and is referenced like this:

sprites.draw(j * 16,i * 16,tilesArray[map1[loopCounter]])

if I reference tilesArray directly, it will pull out the correct tile and display it in place.

For instance, this works fine:
sprites.draw(j * 16,i * 16,tilesArray[map1[1])

If I reference tileArray through map1, it returns junk. I figure it must be because of the format of the return? I’ve tried ints, uint8_t, and unsigned chars but still can’t get it to work. As you can tell, I am a bit of a C rookie!

Can anyone tell me where I am going wrong?

My map1 array looks like this, although I I have tried it as unsigned chars and uint8_t’s as well.

PROGMEM const int map1[] =

and my tiles array like this:

const unsigned char *tilesArray[] = {


You have to use the pgm_read_xxx functions to read data back from program memory placed there using PROGMEM.

1 Like

Awesome, I will try that. Thanks!