#include #include #include #include #include // Image paths and corresponding values const char *images1[] = {"/05_smiley.jpg", "/04_smiley.jpg", "/03_smiley.jpg", "/02_smiley.jpg", "/01_smiley.jpg"}; const int values1[] = {5, 4, 3, 2, 1}; const char *images2[] = {"/50_smiley.jpg", "/40_smiley.jpg", "/30_smiley.jpg", "/20_smiley.jpg", "/10_smiley.jpg"}; const int values2[] = {50, 40, 30, 20, 10}; struct ImageData { const char *src; int value; }; ImageData allImages[] = { {"/smiley_mix11.jpg", 11}, {"/smiley_mix12.jpg", 12}, {"/smiley_mix13.jpg", 13}, {"/smiley_mix14.jpg", 14}, {"/smiley_mix15.jpg", 15}, {"/smiley_mix21.jpg", 21}, {"/smiley_mix22.jpg", 22}, {"/smiley_mix23.jpg", 23}, {"/smiley_mix24.jpg", 24}, {"/smiley_mix25.jpg", 25}, {"/smiley_mix31.jpg", 31}, {"/smiley_mix32.jpg", 32}, {"/smiley_mix33.jpg", 33}, {"/smiley_mix34.jpg", 34}, {"/smiley_mix35.jpg", 35}, {"/smiley_mix41.jpg", 41}, {"/smiley_mix42.jpg", 42}, {"/smiley_mix43.jpg", 43}, {"/smiley_mix44.jpg", 44}, {"/smiley_mix45.jpg", 45}, {"/smiley_mix51.jpg", 51}, {"/smiley_mix52.jpg", 52}, {"/smiley_mix53.jpg", 53}, {"/smiley_mix54.jpg", 54}, {"/smiley_mix55.jpg", 55}, }; int currentIndex1 = 2; int currentIndex2 = 2; const int numImages1 = sizeof(images1) / sizeof(images1[0]); const int numImages2 = sizeof(images2) / sizeof(images2[0]); const int numAllImages = sizeof(allImages) / sizeof(allImages[0]); // TFT and SD TFT_eSPI tft = TFT_eSPI(); void setup() { Serial.begin(115200); delay(1000); // Initialize TFT tft.begin(); tft.setRotation(2); // Adjust as needed tft.fillScreen(TFT_WHITE); // Initialize SD card if (!SD.begin()) { Serial.println("SD card initialization failed!"); return; } Serial.println("SD card initialized."); // Display images based on currentIndex displayJpeg(images1[currentIndex1], 0); displayJpeg(images2[currentIndex2], 1); for (int i = 0; i < numAllImages; i++) { displayJpeg(allImages[i].src, 2); } } void loop() { // Main loop code (if any) } void displayJpeg(const char *filename, int imageIndex) { // Open the file File jpegFile = SD.open(filename, FILE_READ); if (!jpegFile) { Serial.print("Failed to open file "); Serial.println(filename); return; } // Decode the JPEG file if (JpegDec.decodeSdFile(jpegFile)) { jpegRender(imageIndex); } else { Serial.print("JPEG file format not supported for "); Serial.println(filename); } // Close the file jpegFile.close(); } void jpegRender(int imageIndex) { uint16_t *pImg; uint16_t mcu_w = JpegDec.MCUWidth; uint16_t mcu_h = JpegDec.MCUHeight; uint32_t max_x = JpegDec.width; uint32_t max_y = JpegDec.height; // Calculate the vertical and horizontal offsets int16_t x_offset = 0; int16_t y_offset = 0; if (imageIndex == 0) { // First image positioned at 1/4 of TFT width x_offset = tft.width() / 4 - max_x / 2; } else if (imageIndex == 1) { // Second image positioned at 3/4 of TFT width x_offset = 3 * tft.width() / 4 - max_x / 2; } else { // Center third image at the bottom x_offset = (tft.width() - max_x) / 2; y_offset = tft.height() - max_y; } bool swapBytes = tft.getSwapBytes(); tft.setSwapBytes(true); while (JpegDec.read()) { pImg = JpegDec.pImage; int mcu_x = JpegDec.MCUx * mcu_w; int mcu_y = JpegDec.MCUy * mcu_h; uint32_t win_w = (mcu_x + mcu_w <= max_x) ? mcu_w : (max_x % mcu_w); uint32_t win_h = (mcu_y + mcu_h <= max_y) ? mcu_h : (max_y % mcu_h); if ((mcu_x + win_w) <= tft.width() && (mcu_y + win_h) <= tft.height()) { tft.pushImage(mcu_x + x_offset, mcu_y + y_offset, win_w, win_h, pImg); } else if ((mcu_y + win_h) >= tft.height()) { JpegDec.abort(); } } tft.setSwapBytes(swapBytes); }