#include <AnimatedGIF.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#include "badgers.h" // your GIF data in PROGMEM
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_CLK 18
#define TFT_MISO 19
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
AnimatedGIF gif;
// line buffer
uint16_t lineBuffer[320]; // max width of ILI9341
void GIFDraw(GIFDRAW *pDraw) {
int y = pDraw->iY + pDraw->y;
if (y >= tft.height()) return;
uint16_t *palette = pDraw->pPalette;
uint8_t *src = pDraw->pPixels;
for (int x = 0; x < pDraw->iWidth; x++) {
lineBuffer[x] = palette[*src++];
}
tft.setAddrWindow(pDraw->iX, y, pDraw->iWidth, 1);
for (int x = 0; x < pDraw->iWidth; x++) {
tft.pushColor(lineBuffer[x]);
}
}
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(0);
tft.fillScreen(ILI9341_BLACK);
gif.begin(LITTLE_ENDIAN_PIXELS);
}
void loop() {
if (gif.open((uint8_t *)badgers, sizeof(badgers), GIFDraw)) {
Serial.println("GIF opened!");
while (gif.playFrame(true, NULL)) {
// play frames
}
gif.close();
}
}