Need little help with AnimatedGifPanel + Button #297
Replies: 11 comments 24 replies
-
Your cycle while (gifFile) [ ...] is endless. Since the first file in dir is viewed, the condition of while() still true and the program never leave the cycle and never changing the image and not read the button. As a fix try to replace while() to the if() and place button reading code inside the loop |
Beta Was this translation helpful? Give feedback.
-
Hi... the formatting makes your code very hard to understand.. Copy your code to Arduino IDE, do autoalignment with Ctrl-T and you will see that your code follow that way:: Do you already see what is wrong? - when you return to stage 1 - you rewind the root and read the first file again. You should think more about the logic of your program. |
Beta Was this translation helpful? Give feedback.
-
I'm still stuck in the loop. I only get to always play the same one or to pass all the gifs in order, but I can't play one in a loop and change it to the next gif loop with just a button. I've even tried creating multiple folders for each image, or think of multiple buttons for each gif. |
Beta Was this translation helpful? Give feedback.
-
If you changed the code - show the new variant |
Beta Was this translation helpful? Give feedback.
-
I would first assign internal pull up resistor to the button for stable operation. |
Beta Was this translation helpful? Give feedback.
-
Good, I'm happy the 1st step worked well. |
Beta Was this translation helpful? Give feedback.
-
cmon, You get HERE, and have problems with a button?, try one example, using button first, then.... yadi yadi ........... |
Beta Was this translation helpful? Give feedback.
-
do a "list" of all gif files, then point each file as You wish
El dom, 17 jul 2022 a las 7:53, GrimorJander ***@***.***>)
escribió:
… Yes, the Button of my dead.
I add a int count = 0
And my loop look this way now:
`void loop()
{
root = FILESYSTEM.open(gifDir);
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW) {
count++;
Serial.println(count);
gifFile = root.openNextFile();
// C-strings... urghh...
memset(filePath, 0x0, sizeof(filePath));
strcpy(filePath, gifFile.path());
// Show it.
ShowGIF(filePath);
}
}
`
So i can see now a incremental counter on serial monitor... but , how to
say in C++ to show next incremental gif to the loop routine.
—
Reply to this email directly, view it on GitHub
<#297 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIGUX5CBJADCFGNVVFUUSDVUP63VANCNFSM523H6JJA>
.
You are receiving this because you commented.Message ID:
<mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA/repo-discussions/297/comments/3165093
@github.com>
--
David Elias Flores Escalante
TeleTracking SAC
|
Beta Was this translation helpful? Give feedback.
-
then search for SPIFFS examples... |
Beta Was this translation helpful? Give feedback.
-
Finally got it working!! `void loop() buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
}
} } |
Beta Was this translation helpful? Give feedback.
-
@GrimorJander, maybe too late but you might wanna check this lib InterruptButton. With that lib you do not need any loop() tricks, it works on interrupts out of loop() scope. Makes life much easier. |
Beta Was this translation helpful? Give feedback.
-
First of all I want to thank you for this incredible library that has allowed me to make the most of my matrix rgb panels.
I am trying to implement the inner button of the Wroom32 dev board, so that it goes from one gif to the next, in a similar way as it does in the ChainedPanelsAuroraDemo example.
I need that when boot, plays first gif in loop, until i press button, that plays second gif forever, press button next gif in loop and so on.
That way I can play a single gif, but choosing it from several pre-loaded.
So, I'm still a novice and I can only cut and paste code, but I still have a hard time understanding the bugs.
Here´s the code, that only plays first on a loop with button not working properly:
`// Example sketch which shows how to display a 64x32 animated GIF image stored in FLASH memory
// on a 64x32 LED matrix
//
// Credits: https://github.com/bitbank2/AnimatedGIF/tree/master/examples/ESP32_LEDMatrix_I2S
//
#define FILESYSTEM SPIFFS
#include <SPIFFS.h>
#include <AnimatedGIF.h>
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
// ----------------------------
#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.
#define PANEL_CHAIN 1 // Total number of panels chained one to another
#define BTN_PIN 0 // Gif advance. Using EPS32 Boot button.
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
//MatrixPanel_I2S_DMA dma_display;
MatrixPanel_I2S_DMA *dma_display = nullptr;
uint16_t myBLACK = dma_display->color565(0, 0, 0);
uint16_t myWHITE = dma_display->color565(255, 255, 255);
uint16_t myRED = dma_display->color565(255, 0, 0);
uint16_t myGREEN = dma_display->color565(0, 255, 0);
uint16_t myBLUE = dma_display->color565(0, 0, 255);
AnimatedGIF gif;
File f;
int x_offset, y_offset;
// Draw a line of image directly on the LED Matrix
void GIFDraw(GIFDRAW *pDraw)
{
uint8_t *s;
uint16_t *d, *usPalette, usTemp[320];
int x, y, iWidth;
iWidth = pDraw->iWidth;
if (iWidth > MATRIX_WIDTH)
iWidth = MATRIX_WIDTH;
} /* GIFDraw() */
void * GIFOpenFile(const char *fname, int32_t *pSize)
{
Serial.print("Playing gif: ");
Serial.println(fname);
f = FILESYSTEM.open(fname);
if (f)
{
*pSize = f.size();
return (void )&f;
}
return NULL;
} / GIFOpenFile() */
void GIFCloseFile(void *pHandle)
{
File *f = static_cast<File >(pHandle);
if (f != NULL)
f->close();
} / GIFCloseFile() */
int32_t GIFReadFile(GIFFILE *pFile, uint8_t *pBuf, int32_t iLen)
{
int32_t iBytesRead;
iBytesRead = iLen;
File *f = static_cast<File >(pFile->fHandle);
// Note: If you read a file all the way to the last byte, seek() stops working
if ((pFile->iSize - pFile->iPos) < iLen)
iBytesRead = pFile->iSize - pFile->iPos - 1; // <-- ugly work-around
if (iBytesRead <= 0)
return 0;
iBytesRead = (int32_t)f->read(pBuf, iBytesRead);
pFile->iPos = f->position();
return iBytesRead;
} / GIFReadFile() */
int32_t GIFSeekFile(GIFFILE *pFile, int32_t iPosition)
{
int i = micros();
File *f = static_cast<File >(pFile->fHandle);
f->seek(iPosition);
pFile->iPos = (int32_t)f->position();
i = micros() - i;
// Serial.printf("Seek time = %d us\n", i);
return pFile->iPos;
} / GIFSeekFile() */
unsigned long start_tick = 0;
void ShowGIF(char *name)
{
start_tick = millis();
if (gif.open(name, GIFOpenFile, GIFCloseFile, GIFReadFile, GIFSeekFile, GIFDraw))
{
x_offset = (MATRIX_WIDTH - gif.getCanvasWidth())/2;
if (x_offset < 0) x_offset = 0;
y_offset = (MATRIX_HEIGHT - gif.getCanvasHeight())/2;
if (y_offset < 0) y_offset = 0;
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
Serial.flush();
while (gif.playFrame(true, NULL))
{
if ( (millis() - start_tick) > 8000) { // we'll get bored after about 8 seconds of the same looping gif
break;
}
}
gif.close();
}
} /* ShowGIF() */
/************************* Arduino Sketch Setup and Loop() *******************************/
void setup() {
//
HUB75_I2S_CFG mxconfig(
PANEL_RES_X, // module width
PANEL_RES_Y, // module height
PANEL_CHAIN // Chain length
);
mxconfig.gpio.e = 18;
mxconfig.clkphase = false;
mxconfig.driver = HUB75_I2S_CFG::FM6126A;
// Display Setup
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
dma_display->setBrightness8(90); //0-255
dma_display->clearScreen();
dma_display->fillScreen(myWHITE);
//
Serial.begin(115200);
Serial.println("Starting AnimatedGIFs Sketch");
// Start filesystem
Serial.println(" * Loading SPIFFS");
if(!SPIFFS.begin()){
Serial.println("SPIFFS Mount Failed");
}
dma_display->begin();
/* all other pixel drawing functions can only be called after .begin() */
dma_display->fillScreen(dma_display->color565(0, 0, 0));
gif.begin(LITTLE_ENDIAN_PIXELS);
}
String gifDir = "/gifs"; // play all GIFs in this directory on the SD card
char filePath[256] = { 0 };
File root, gifFile;
void loop()
{
while (1) // run forever
{
// Boot button Gif advance with debounce
int reading = digitalRead(BTN_PIN);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
} // while
}`
Any help will be apreciated.
Beta Was this translation helpful? Give feedback.
All reactions