javl / image2cpp

GNU General Public License v3.0
537 stars 160 forks source link

Calling images from array #25

Closed gc9n closed 5 years ago

gc9n commented 5 years ago

its not an issue , but i need some help about how to call multiple images

i have 100 array images like that

const unsigned char load1 []  = {
    0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00,
    0x60, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0e, 0x00, 0x06, 0x00, 0x00, 0x00
};
// 'tmp-1', 15x15px
const unsigned char load2 []  = {
    0x00, 0x00, 0x00, 0x40, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x0c, 0x60, 0x0c,
    0x60, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x00, 0x00
};
// 'tmp-2', 15x15px
const unsigned char load3 []  = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x60, 0x0c, 0x60, 0x0c,
    0x60, 0x0c, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'tmp-3', 15x15px
const unsigned char load4 []  = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x20, 0x18, 0x60, 0x0c, 0x60, 0x0c, 0x60, 0x0c,
    0x60, 0x0c, 0x60, 0x0c, 0x30, 0x08, 0x18, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'tmp-4', 15x15px
const unsigned char load5 []  = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0x18, 0x60, 0x0c, 0x60, 0x0c, 0x60, 0x0c,
    0x60, 0x0c, 0x60, 0x0c, 0x30, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
.....
const unsigned char load100 []  = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0x18, 0x60, 0x0c, 0x60, 0x0c, 0x60, 0x0c,
    0x60, 0x0c, 0x60, 0x0c, 0x30, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

in order to prevent calling them one by one

drawBitmap(0, 0,**load1**, 15, 15);
drawBitmap(0, 0,**load2**, 15, 15);
drawBitmap(0, 0,**load3**, 15, 15);
...
drawBitmap(0, 0,**load100**, 15, 15);

how can i call them in a loop?

for (int8_t j = 0; j <= 100; j = j + 1) {
    drawBitmap(0, 0,load+ i, 15, 15);
}

i need some kind of populated execute function

javl commented 5 years ago

I prefer to keep these kind of questions on other platforms (Stackoverflow, the Arduino forum) as the problem is not specific to this project, there are already many examples of similar problems on those sites and it muddies the issue tracker.

That being said, this should do the trick ;) (don't forget to add the code to load the Adafruit library)

// Define the amount of images we want to use
#define NUM_IMAGES 3

// first [] are the images in our array (we don't have to specify the amount because
// we provide the data as a list { ... }, but as we need the amount later for the for
// loop anyway, I've specified the amount here as well 
// second [] is the amount of characters needed for each image, in this case we have 30 chars
// for each image 
const unsigned char images[NUM_IMAGES][30] = {
  {
    0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00,
    0x60, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0e, 0x00, 0x06, 0x00, 0x00, 0x00
  },
  {
    0x00, 0x00, 0x00, 0x40, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x0c, 0x60, 0x0c,
    0x60, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x00, 0x00
  },
  {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x60, 0x0c, 0x60, 0x0c,
    0x60, 0x0c, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00
  }
};

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  for (int8_t i = 0; i <= NUM_IMAGES; i++) {
    drawBitmap(0, 0, images[i], 15, 15);
  }
}
gc9n commented 5 years ago

thank you !!!