i am on a project where i am using a tft display and a node mcu -12E, i wanna make a code where i first upload around 15 animations to the esp then i want to access them when i click a button
for example if i click the button one the counter must increase by one and must show the first animation and so on. i have no clue how to acess the files in the flash memory i need a method to access the files individually and not load it in the display and delete it from the ram as ram space is not needed and so its more efficient. how can i make this work. this is my code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <FS.h>
#include <>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(115200);
// Initialize SPIFFS
if (!SPIFFS.begin()) {
Serial.println("Failed to mount file system");
return;
}
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Displaying GIF frames:");
display.display();
delay(2000); // Delay for readability
display.clearDisplay();
}
void loop() {
// Display each frame from SPIFFS
for (int frameNumber = 1; frameNumber <= 10; frameNumber++) { // Adjust the number of frames accordingly
String frameFileName = "/frame" + String(frameNumber) + ".bmp";
displayFrameFromFile(frameFileName);
delay(100); // Adjust delay to control frame rate
}
}
void displayFrameFromFile(String filename) {
File file = SPIFFS.open(filename, "r");
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
uint16_t read;
uint32_t seekAddr = 0;
// Read BMP header (24 bytes) and ignore
for (read = 0; read < 24; read++) {
file.read();
}
// Read image data and display
for (uint8_t y = 0; y < SCREEN_HEIGHT; y++) {
for (uint8_t x = 0; x < SCREEN_WIDTH; x++) {
uint8_t b = file.read();
uint8_t g = file.read();
uint8_t r = file.read();
uint16_t color = display.color565(r, g, b);
display.drawPixel(x, y, color);
}
}
// Close the file
file.close();
display.display();
}
i tried to access the file but it doesnt function properly i expect it to show the animation when the button is clicked
Tenuka Perera is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.