Created
May 3, 2023 07:50
-
-
Save hpwit/a78a1de51ad290439df9827e49033c66 to your computer and use it in GitHub Desktop.
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 "FastLED.h" | |
#include "freertos/queue.h" | |
#include "freertos/semphr.h" | |
#include "SD.h" | |
#include "SPI.h" | |
#define NUM_LEDS 5184 | |
#define LEDS_PER_PIN (NUM_LEDS / 6) | |
#define QUEUE_SIZE 50 | |
#define DELAY_FRAMES 10 //to set up the delay between frames you'll not be doing more than 36fps anyway | |
CRGB leds[NUM_LEDS]; | |
CRGB buffer[NUM_LEDS]; | |
File myFile; | |
//this is to indicate that a new frame is ready | |
static xQueueHandle _frame_queue; | |
static TaskHandle_t _displayFrameTaskhandle; | |
volatile xSemaphoreHandle diplay_sem = NULL; | |
volatile xSemaphoreHandle transfer_sem = NULL; | |
bool sd_card_present=false; | |
static void displayframe(void *pvParameters) | |
{ | |
for(;;) | |
{ | |
xSemaphoreTake(diplay_sem, portMAX_DELAY); | |
FastLED.show(); | |
xSemaphoreGive(transfer_sem); | |
} | |
} | |
void stripsConfig() { | |
FastLED.addLeds<WS2812B, 12, EOrder::GRB>(leds, 0 * LEDS_PER_PIN, LEDS_PER_PIN); | |
FastLED.addLeds<WS2812B, 13, EOrder::GRB>(leds, 1 * LEDS_PER_PIN, LEDS_PER_PIN); | |
FastLED.addLeds<WS2812B, 16, EOrder::GRB>(leds, 2 * LEDS_PER_PIN, LEDS_PER_PIN); | |
FastLED.addLeds<WS2812B, 17, EOrder::GRB>(leds, 3 * LEDS_PER_PIN, LEDS_PER_PIN); | |
FastLED.addLeds<WS2812B, 18, EOrder::GRB>(leds, 4 * LEDS_PER_PIN, LEDS_PER_PIN); | |
FastLED.addLeds<WS2812B, 19, EOrder::GRB>(leds, 5 * LEDS_PER_PIN, LEDS_PER_PIN); | |
} | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
//strip init | |
stripsConfig(); | |
//queue init | |
diplay_sem = xSemaphoreCreateBinary(); | |
transfer_sem = xSemaphoreCreateBinary(); | |
//init displatyframe task on second core | |
xTaskCreateUniversal(displayframe, "displayframe", 4096, NULL, 3, &_displayFrameTaskhandle, 0); | |
//init SD card | |
if(!SD.begin()){ | |
Serial.println("Card Mount Failed"); | |
sd_card_present=false; | |
} | |
else | |
{ | |
uint8_t cardType = SD.cardType(); | |
if(cardType == CARD_NONE){ | |
Serial.println("No SD card attached"); | |
sd_card_present=false; | |
} | |
else | |
{ | |
sd_card_present=true; | |
} | |
} | |
//open the file | |
myFile=SD.open("/video1.txt"); //to change with your filename | |
if (myFile) Serial.println("FILE_OK"); | |
xSemaphoreGive(transfer_sem); | |
} | |
bool readNextFrame(File sdfile) | |
{ | |
if (sdfile.available() > 0) | |
{ | |
sdfile.read((uint8_t *)buffer, NUM_LEDS*3); | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if(sd_card_present) | |
{ | |
if (!readNextFrame(myFile)) | |
{ | |
//loop over the file | |
myFile.seek(0); | |
} | |
else | |
{ | |
xSemaphoreTake(transfer_sem, portMAX_DELAY); | |
memcpy(leds,buffer,NUM_LEDS*3); | |
xSemaphoreGive(diplay_sem); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment