#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
// Твои пины подключения
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define SD_CS 13
#define BUTTON 1
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
pinMode(BUTTON, INPUT_PULLUP);
tft.initR(INITR_BLACKTAB);
tft.setRotation(1); // 160x128
tft.fillScreen(ST77XX_BLACK);
if (!SD.begin(SD_CS)) {
tft.fillScreen(ST77XX_RED); // Красный экран, если флешку не видно
while (1);
}
drawBMP("/IL1.bmp");
}
void loop() {
if (digitalRead(BUTTON) == LOW) {
delay(50);
if (digitalRead(BUTTON) == LOW) {
playAVI("/IL2.avi");
drawBMP("/IL1.bmp");
}
}
}
void drawBMP(const char* filename) {
File bmpFile = SD.open(filename);
if (!bmpFile) return;
uint32_t dataOffset = 0;
bmpFile.seek(10);
bmpFile.read((uint8_t*)&dataOffset, 4);
bmpFile.seek(dataOffset);
for (int16_t y = 127; y >= 0; y--) {
for (int16_t x = 0; x < 160; x++) {
int b1 = bmpFile.read();
int b2 = bmpFile.read();
if (b1 == -1 || b2 == -1) break;
uint16_t color = ((uint16_t)b2 << 8) | (uint16_t)b1;
tft.drawPixel(x, y, color);
}
}
bmpFile.close();
}
void playAVI(const char* filename) {
File aviFile = SD.open(filename);
if (!aviFile) return;
int16_t x = 0; int16_t y = 0;
while (aviFile.available()) {
int b1 = aviFile.read();
if (b1 == -1) break;
if (b1 == 0xFF) {
int b2 = aviFile.peek();
if (b2 == 0xD8) {
aviFile.read();
x = 0; y = 0;
while (aviFile.available()) {
int p1 = aviFile.read();
if (p1 == -1) break;
if (p1 == 0xFF) {
int p2 = aviFile.peek();
if (p2 == 0xD9) { aviFile.read(); break; }
}
int p2 = aviFile.read();
if (p2 == -1) break;
uint16_t color = ((uint16_t)p1 << 8) | (uint16_t)p2;
tft.drawPixel(x, y, color);
x++;
if (x >= 160) { x = 0; y++; if (y >= 128) break; }
}
delay(20);
}
}
}
aviFile.close();
}