I did see Aurora thanks but i would like to try and do it myself…
Thanks Louis i didnt realize the order of the layers, that fixed that issue. Hopefully you can help me with the below issue also…
I have the clock running on top of the GIFS while they play but i have a little issue that i just cant work out. On initial power-on the gifs play but the clock is not updated until three gifs have played and only then the correct time will be displayed. The clock is displayed but only ever gets updated always after three gifs have been played.
`
#include <SmartMatrix3.h>
#include <SPI.h>
#include <SD.h>
#include "GIFDecoder.h"
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
#define CLOCK 1
#define GIF 1
#define DISPLAY_TIME_SECONDS 1
#define ENABLE_SCROLLING 0
// range 0-255
const int defaultBrightness = 30;
const rgb24 COLOR_BLACK = {
0, 0, 0 };
/* SmartMatrix configuration and memory allocation */
#define COLOR_DEPTH 24
const uint8_t kMatrixWidth = 64; // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 64; // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 24; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 2; // known working: 2-4
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE); // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
SMARTMATRIX_ALLOCATE_INDEXED_LAYER(indexedLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kIndexedLayerOptions);
#if ENABLE_SCROLLING == 1
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
#endif
// Chip select for SD card on the SmartMatrix Shield
#define SD_CS 15
#define GIF_DIRECTORY "/gifs/"
int num_files;
void screenClearCallback(void) {
backgroundLayer.fillScreen({0,0,0});
}
void updateScreenCallback(void) {
backgroundLayer.swapBuffers();
}
void drawPixelCallback(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue) {
backgroundLayer.drawPixel(x, y, {red, green, blue});
}
const SM_RGB clockColor = {0xff, 0xff, 0xff};
// Setup method runs once, when the sketch starts
void setup() {
setScreenClearCallback(screenClearCallback);
setUpdateScreenCallback(updateScreenCallback);
setDrawPixelCallback(drawPixelCallback);
// Seed the random number generator
randomSeed(analogRead(14));
Serial.begin(115200);
// Initialize matrix
matrix.addLayer(&backgroundLayer);
matrix.addLayer(&indexedLayer);
#if ENABLE_SCROLLING == 1
matrix.addLayer(&scrollingLayer);
#endif
matrix.begin();
/* I2C Changes Needed for SmartMatrix Shield */
// switch pins to use 16/17 for I2C instead of 18/19, after calling matrix.begin()//
pinMode(18, INPUT);
pinMode(19, INPUT);
CORE_PIN16_CONFIG = (PORT_PCR_MUX(2) | PORT_PCR_PE | PORT_PCR_PS);
CORE_PIN17_CONFIG = (PORT_PCR_MUX(2) | PORT_PCR_PE | PORT_PCR_PS);
// display a simple message - will stay on the screen if calls to the RTC library fail later
indexedLayer.fillScreen(0);
indexedLayer.setFont(gohufont11b);
indexedLayer.drawString(0, kMatrixHeight / 2 - 6, 1, " CLOCK");
indexedLayer.swapBuffers(false);
matrix.setRefreshRate(60);
// for large panels, set the refresh rate lower to leave more CPU time to decoding GIFs (needed if GIFs are playing back slowly)
// Clear screen
backgroundLayer.fillScreen(COLOR_BLACK);
backgroundLayer.swapBuffers();
// initialize the SD card at full speed
pinMode(SD_CS, OUTPUT);
if (!SD.begin(SD_CS)) {
#if ENABLE_SCROLLING == 1
scrollingLayer.start("No SD card", -1);
#endif
Serial.println("No SD card");
while(1);
}
// Determine how many animated GIF files exist
num_files = enumerateGIFFiles(GIF_DIRECTORY, false);
if(num_files < 0) {
#if ENABLE_SCROLLING == 1
scrollingLayer.start("No gifs directory", -1);
#endif
Serial.println("No gifs directory");
while(1);
}
if(!num_files) {
#if ENABLE_SCROLLING == 1
scrollingLayer.start("Empty gifs directory", -1);
#endif
Serial.println("Empty gifs directory");
while(1);
}
}
void loop() {
#if (CLOCK == 1)
Serial.println("Main loop start again");
tmElements_t tm;
int x = kMatrixWidth/2-15;
char timeBuffer[9];
// clear screen before writing new text
indexedLayer.fillScreen(0);
if (RTC.read(tm)) {
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
/* Draw Clock to SmartMatrix */
uint8_t hour = tm.Hour;
Serial.println("draw to matrix.");
if (hour > 12)
hour -= 12;
sprintf(timeBuffer, "%d:%02d", hour, tm.Minute);
if (hour < 10)
x += 3;
indexedLayer.setFont(gohufont11b);
indexedLayer.drawString(x, kMatrixHeight / 2 - 6, 1, timeBuffer);
indexedLayer.swapBuffers();
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
/* Draw Error Message to SmartMatrix */
indexedLayer.setFont(font3x5);
sprintf(timeBuffer, "Stopped");
indexedLayer.drawString(x, kMatrixHeight / 2 - 3, 1, "Stopped");
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
/* Draw Error Message to SmartMatrix */
indexedLayer.setFont(font3x5);
indexedLayer.drawString(x, kMatrixHeight / 2 - 3, 1, "No Clock");
}
indexedLayer.swapBuffers(false);
delay(9000);
}
delay(1000);
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
#endif
#if (GIF == 1)
{
matrix.setBrightness(defaultBrightness);
unsigned long futureTime;
char pathname[30];
int index = random(num_files);
// Do forever
// while (true) {
// Can clear screen for new animation here, but this might cause flicker with short animations
// matrix.fillScreen(COLOR_BLACK);
// matrix.swapBuffers();
getGIFFilenameByIndex(GIF_DIRECTORY, index++, pathname);
if (index >= num_files) {
index = 0;
}
// Calculate time in the future to terminate animation
futureTime = millis() + (DISPLAY_TIME_SECONDS * 1000);
while (futureTime > millis()) {
processGIFFile(pathname);
int x = kMatrixWidth/2-15;
}
}
#endif
}
`
Thanks Daniel