Created
October 25, 2020 19:57
-
-
Save acedrew/8fb4ddb5df956fcc3e97de7e708635b7 to your computer and use it in GitHub Desktop.
GIF player for M5StickC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5StickC.h> | |
#include <SPIFFS.h> | |
#define BUTTON G37 | |
bool loaded = false; | |
uint16_t buffer[12800]; | |
uint8_t i = 7; | |
File dir; | |
File frame; | |
uint8_t current_gif = 0; | |
String gifs[] = { | |
"/meteoright" | |
}; | |
String fileNames[50] = {""}; | |
uint8_t frameCount = 0; | |
uint8_t framePos = 0; | |
void readFiles() { | |
uint8_t i = 0; | |
dir = SPIFFS.open(gifs[current_gif], "r+"); | |
frame = dir.openNextFile(); | |
while(frame) { | |
fileNames[i] = frame.name(); | |
frame.close(); | |
frame = dir.openNextFile(); | |
i++; | |
} | |
frameCount = i; | |
dir.close(); | |
} | |
void setup() { | |
// Serial.begin(115200); | |
SPIFFS.begin(); | |
// if(!SPIFFS.begin()){ | |
// Serial.println("An Error has occurred while mounting SPIFFS"); | |
// } | |
// Serial.println(SPIFFS.totalBytes()); | |
// SPIFFS.begin(); | |
M5.begin(); | |
M5.Lcd.setRotation(3); | |
// M5.Lcd.fillScreen(WHITE); | |
} | |
void loop() { | |
if(!digitalRead(BUTTON) && loaded) { | |
// dir.close(); | |
current_gif = (current_gif + 1) % 3; | |
loaded = false; | |
return; | |
} | |
if (!loaded) { | |
readFiles(); | |
// dir = SPIFFS.open(gifs[current_gif], "r+"); | |
// frame = dir.openNextFile(); | |
// File dir = SPIFFS.open("/", "r+"); | |
// File frame = dir.openNextFile(); | |
loaded = true; | |
} | |
// Serial.println(dir.name()); | |
// Serial.println(frame.name()); | |
frame = SPIFFS.open(fileNames[framePos]); | |
frame.readBytes((char *) &buffer, 25600); | |
M5.Lcd.drawBitmap(0, 0, 160, 80, buffer); | |
frame.close(); | |
framePos = (framePos + 1) % frameCount; | |
if(framePos != 0) { | |
delay(30); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment