Skip to content

Instantly share code, notes, and snippets.

@hpwit
Last active August 18, 2018 13:01
Show Gist options
  • Select an option

  • Save hpwit/23e32fdd791a4dca1f69ada3e1eb0658 to your computer and use it in GitHub Desktop.

Select an option

Save hpwit/23e32fdd791a4dca1f69ada3e1eb0658 to your computer and use it in GitHub Desktop.
#include <Adafruit_GFX.h>
#include <FastLED.h>
#include <FastLED_NeoMatrix.h>
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);
#define mw 80
#define mh 32
#define NUMMATRIX (mw*mh)
#define LED_RUN_LENGTH 16//number of leds per column
CRGB matrixleds[NUMMATRIX];
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(matrixleds,16,16,5,2,
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS +NEO_TILE_ZIGZAG+
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG );
const uint16_t colors[] = {
matrix->Color(255, 0, 0), matrix->Color(0, 255, 0), matrix->Color(0, 0, 255) };
//-------------------------------
#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Artnet.h>
#include "SD.h"
#include "SPI.h"
//#define FASTLED_ALLOW_INTERRUPTS 0
//#define INTERRUPT_THRESHOLD 1
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#define FASTLED_SHOW_CORE 0
#define LED_WIDTH 80
#define LED_HEIGHT 32
#define NUM_LEDS LED_WIDTH*LED_HEIGHT
#define UNIVERSE_SIZE 170
#define PIXEL_PER_PIN NUM_LEDS/5
/*we will use 5 pins each pin will drive two 16x16 panel hence 512 pix it will take 15ms to refresh your entire panel instead of 76ms
hence having a refresh rate of 65fps instead of 13fps*/
#define PIN1 2
#define PIN2 4
#define PIN3 27
#define PIN4 12
#define PIN5 13
//CRGB leds[NUM_LEDS];
uint8_t readbuffer[NUM_LEDS*3];
char filename[256];
char READ_NAME[]="savedata"; //the name of your save
//Artnet artnet;
File root;
File myFile;
static TaskHandle_t FastLEDshowTaskHandle = 0;
static TaskHandle_t FastLEDshowTaskHandle2 = 0;
static TaskHandle_t userTaskHandle = 0;
#define BRIGHTNESS 100
char datestring[20];
void FastLEDshowESP32()
{
if (userTaskHandle == 0) {
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
// -- Store the handle of the current task, so that the show task can
// notify it when it's done
// noInterrupts();
userTaskHandle = xTaskGetCurrentTaskHandle();
// -- Trigger the show task
xTaskNotifyGive(FastLEDshowTaskHandle);
// -- Wait to be notified that it's done
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS( 500 ));//portMAX_DELAY);
//delay(100);
//interrupts();
userTaskHandle = 0;
}
}
/*
void FastLEDshowESP322()
{
if (userTaskHandle == 0) {
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
// -- Store the handle of the current task, so that the show task can
// notify it when it's done
// noInterrupts();
userTaskHandle = xTaskGetCurrentTaskHandle();
// -- Trigger the show task
xTaskNotifyGive(FastLEDshowTaskHandle2);
//to thge contrary to the other one we do not wait for the display task to come back
}
}
*/
void FastLEDshowTask(void *pvParameters)
{
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 500 );
// -- Run forever...
for(;;) {
// -- Wait for the trigger
ulTaskNotifyTake(pdTRUE,portMAX_DELAY);
FastLED.show();
xTaskNotifyGive(userTaskHandle);
}
}
void setup() {
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(115200);
// xTaskCreatePinnedToCore(FastLEDshowTask2, "FastLEDshowTask2", 1000, NULL,3, &FastLEDshowTaskHandle2, FASTLED_SHOW_CORE);
xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 3000, NULL,3, &FastLEDshowTaskHandle, FASTLED_SHOW_CORE);
/* WiFi.mode(WIFI_STA);
Serial.printf("Connecting ");
WiFi.begin("", "");
while (WiFi.status() != WL_CONNECTED) {
Serial.println(WiFi.status());
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
*/
if(!SD.begin(5,SPI,80000000)){
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD card attached");
return;
}
memset(filename, 0, 255);
sprintf(filename,"/%s.dat",READ_NAME);
myFile = SD.open(filename);
FastLED.addLeds<WS2812B, PIN1, GRB>(matrixleds, 0*PIXEL_PER_PIN, PIXEL_PER_PIN);
FastLED.addLeds<WS2812B, PIN2, GRB>(matrixleds, 1*PIXEL_PER_PIN, PIXEL_PER_PIN);
FastLED.addLeds<WS2812B, PIN3, GRB>(matrixleds, 2*PIXEL_PER_PIN, PIXEL_PER_PIN);
FastLED.addLeds<WS2812B, PIN4, GRB>(matrixleds, 3*PIXEL_PER_PIN, PIXEL_PER_PIN);
FastLED.addLeds<WS2812B, PIN5, GRB>(matrixleds, 4*PIXEL_PER_PIN, PIXEL_PER_PIN);
//FastLED.addLeds<NEOPIXEL,PIN3>(matrixleds, NUMMATRIX);
Rtc.Begin();
matrix->begin();
matrix->setTextWrap(true);
matrix->setBrightness(40);
matrix->setTextColor(colors[0]);
}
void loop() {
// artnet.read();
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
if (myFile.available())
{
myFile.read(readbuffer,NUM_LEDS*sizeof(CRGB));
memcpy(matrixleds,readbuffer,NUM_LEDS*sizeof(CRGB));
matrix->print (datestring);
FastLEDshowESP32();
//matrix->show();
//delay(20); //this is to be changed to adapt the replay
}
else
{
myFile.seek(0);
}
}
void printDateTime(const RtcDateTime& dt)
{
sprintf(datestring,"%02u:%02u:%02u", dt.Hour(), dt.Minute(), dt.Second());
Serial.print(datestring);
matrix->clear();
matrix->setCursor(0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment