Hi,
I want to read HEX code made from BMP from the SD card and than displaying it on the OLED display.
I don’t have problems with reading file, but I don’t know how to convert data from it to the “static const unsigned char” in which the image should be stored.
Here’s my code:
//Pretty normal stuff
#include <SPI.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <SD.h>
File myFile;
#define filePath "logo.txt"
//OLED pins
#define OLED_DC 4 //OLED -- D/C
#define OLED_CS 8 //Not connect
#define OLED_CLK 7 //OLED -- SCL
#define OLED_MOSI 6 //OLED -- SDA
#define OLED_RESET 5//OLED -- RST
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
//And here we've got our char
static const unsigned char PROGMEM Logo[] = {
//blah blah blah
};
void setup(void)
{
Serial.begin(115200);
//OLED initialization
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
if (!SD.begin(3)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open(filePath);
if (myFile) {
Serial.println(filePath);
while (myFile.available()) {
Serial.write(myFile.read());
}
} else {
Serial.println("error opening logo.txt");
}
//------------
//And here i want to read data from file and overwrite current char so it can be displayed as image later.
//How am I supposed to do this?
//------------
static const unsigned char PROGMEM Logo[] = {myFile.read()};
myFile.close();
}
//Again, pretty normal stuff
void loop()
{
display.clearDisplay();
display.drawBitmap(32, 0, Logo, 64, 64, 1);
display.display();
delay(500);
}
I run it on the Mega cause Uno doesn’t have enough memory.
I hope someone can help me with this, thanks!