How do you Play GIF files with push button trigger


#1

How do you Play GIF files with push button trigger?


#2

You’re going to have to write some code to do this. You can use the AnimatedGIFs example as a starting point. Look at some other Arduino code that shows how to do something - like blink an LED - from a button. You can write a function that loads a GIF file when a button is pressed. Check out this thread for some more details on how to modify the AnimatedGIFs sketch to play a specific file: GIF playback by filename


#3

Seem to be getting somewhere now just keep on getting a error message in serial monitor when push button is activated ware am i going wrong? the error message is “Error opening GIF file” Here is the code i have put together
int openGifFilenameByIndex(const char *directoryName, int index) {
char pathname[30];

getGIFFilenameByIndex(directoryName, index, pathname);

pinMode(9, INPUT_PULLUP);

int sensorVal = digitalRead(9);

//print out the value of the pushbutton
Serial.println(sensorVal);
Serial.print("pathname: ");
Serial.println(pathname);

if (file)
file.close();

if (sensorVal == HIGH)
// Attempt to open the file for reading
file = SD.open("/gifs/1.GIF");
if (!file)
Serial.println(“Error opening GIF file”);
return -1;

return 0;


#4

I don’t see anything directly wrong with this that would cause the error message to show up. You aren’t using brackets or indentation around some of your if() statements, and that might make it hard to read, or cause some bugs:

if (sensorVal == HIGH)
// Attempt to open the file for reading
file = SD.open("/gifs/1.GIF");
if (!file)
Serial.println(“Error opening GIF file”);
return -1;

This is better:

if (sensorVal == HIGH) {
    // Attempt to open the file for reading
    file = SD.open("/gifs/1.GIF");
}
if (!file) {
    Serial.println(“Error opening GIF file”);
    return -1;
}

There’s no actual change in the first if(), but the second if() should both print and return -1, and it wasn’t before.

Sorry I don’t think this helps you get it working.