Display bitmaps from sd

I have a 3.5 spi tft ili9486 disply and i can display an image on screen as a 16 color 565 with this code :
Void Draw_Bit_Map(int16_t x, int16_t y, int16_t sx, int16_t
sy, const uint16_t *data, int16_t scale)
I use mega thats have a small of memory and i want a showing a plenty of images one after another like mobile screen .
I stored variables in arrays in txt file in sd card like the following example . How can I read the data from txt file in sd card as a uint16 array to dislay an image then delete data to get another for next image.

I stored the data of bitmaps in arrays like this :

const uint16_t car [  ] ={0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe79e, 0xc71c, 0x9e39, 0xa67a, 0xcf1c, 0xf7df, 0xffff, 0xffff, 
0xd6ba, 0xbdf7, 0xbdd7, 0xbdd7, 0xf7be, 0xffff, 0xe7be, 0xcf1c, 0x9659, 0x9619, 0x7535, 0x9e39, 0xcefc, 0xffff, 0xffff, 0xdefb, 
0xc638, 0xce59, 0xdefb, 0xffdf, 0xefbe, 0xc71c, 0xa6bb, 0x8dd7, 0x6d56, 0x7556, 0x6d35, 0xa67a, 0xefbe, 0xffff, 0xffff, 0xffff, 
0xffff, 0xffff, 0xf7df, 0xd73c, 0xbedb, 0x85b7, 0x7d97, 0x64d4, 0x6536, 0x6d15, 0x8d96, 0xe77d, 0xffff, 0xffff, 0xffff, 0xef9e, 
0xdf3d, 0xcefc, 0xc69b, 0xae7a, 0x8576, 0x64d4, 0x6536, 0x5cf5, 0x7dd8, 0x9618, 0xdf7e, 0xffff, 0xffff, 0xe73d, 0xcebb, 0xbe39, 
0xad98, 0xad37, 0x94b7, 0x6d37, 0x6cd4, 0x5cf5, 0x85d8, 0x8596, 0xc6fc, 0xefbf, 0xffff, 0xe75d, 0xc63a, 0xbe19, 0xa577, 0x9cf6, 
0xa456, 0xa3b6, 0x7bd6, 0x85b8, 0x95f8, 0x8e19, 0xbe9a, 0xefbe, 0xffff, 0xffff, 0xce19, 0xa536, 0xadd8, 0x74d4, 0x5c52, 0x73d3, 
0xabb7, 0xa3b7, 0xa5fa, 0xb6db, 0xc6dc, 0xf7bf, 0xffff, 0xffff, 0xffdf, 0xc5d8, 0x9d35, 0x8d15, 0x5492, 0x95d7, 0x6452, 0xa356, 
0xb418, 0xbdfb, 0xcf1d, 0xf7bf, 0xffff, 0xffff, 0xffff, 0xf7df, 0xc5fa, 0xad97, 0x8d55, 0x64b2, 0xbe99, 0x6c93, 0xa376, 0xb418, 
0xce7c, 0xf7df, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xce5b, 0xad97, 0xa597, 0x7cf4, 0x6c73, 0x83b4, 0xa376, 0xabb8, 0xdf1d, 
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdf1d, 0xad77, 0xad97, 0x9d56, 0x8c74, 0x9c75, 0x9475, 0xbd39, 0xf7bf, 0xffff, 
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf7df, 0xce7b, 0xb5d8, 0xa576, 0xa576, 0xad97, 0xbd79, 0xe75d, 0xffff, 0xffff, 0xffff, 
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf7df, 0xdf1c, 0xc6ba, 0xc69a, 0xcefc, 0xef9e, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf7df, 0xf7df, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
0xffff};

do you mean the code you posted is how the data looks in the file on the SD card? (I added code tags, do yourself a favour and please read How to get the best out of this forum for next time and use code tags).

that's not the most effective way to represent the bitmap, you can't interpret that code at run time. You would need to write a parser. Ideally you would actually write the bitmaps in binary format in separate files and you would then just read the file into a local buffer before calling Draw_Bit_Map()

that's a crude example on how you would copy that file into memory

#include <SD.h>

const size_t maxBitmapSize = 200;
byte tmpBitmap[maxBitmapSize];

void setup() {
  Serial.begin(115200); Serial.println();

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin()) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

  File bitmapFile = SD.open("bitmap.bin"); // whatever file name you want
  if (bitmapFile) {
    size_t fileSize = bitmapFile.size();
    if (fileSize <= maxBitmapSize) {
      bitmapFile.read(tmpBitmap, fileSize);
      bitmapFile.close();
      // here you have your buffer ready to use
      // ... do something with it
    } else {
      // bitmap too big for the temp buffer we have created
    }
  } else {
    // error could not open the bitmap file
  }

}

void loop() {}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.