Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 / 8)
- #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;
- static xQueueHandle _frame_queue;
- static TaskHandle_t _displayFrameTaskhandle;
- volatile xSemaphoreHandle diplay_sem = NULL;
- volatile xSemaphoreHandle transfer_sem = NULL;
- bool SD_OK = false;
- static void displayframe(void *pvParameters)
- {
- for (;;)
- {
- xSemaphoreTake(diplay_sem, portMAX_DELAY);
- FastLED.show();
- xSemaphoreGive(transfer_sem);
- }
- }
- void stripsConfig() {
- FastLED.addLeds<WS2812B, 13, EOrder::GRB>(leds, 0 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 12, EOrder::GRB>(leds, 1 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 14, EOrder::GRB>(leds, 2 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 27, EOrder::GRB>(leds, 3 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 26, EOrder::GRB>(leds, 4 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 25, EOrder::GRB>(leds, 5 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 33, EOrder::GRB>(leds, 6 * LEDS_PER_PIN, LEDS_PER_PIN);
- FastLED.addLeds<WS2812B, 32, EOrder::GRB>(leds, 7 * LEDS_PER_PIN, LEDS_PER_PIN);
- }
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- stripsConfig();
- sdStart();
- diplay_sem = xSemaphoreCreateBinary();
- transfer_sem = xSemaphoreCreateBinary();
- xTaskCreateUniversal(displayframe, "displayframe", 4096, NULL, 3, &_displayFrameTaskhandle, 0);
- 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() {
- if (SD_OK) {
- if (!readNextFrame(myFile)) {
- myFile.seek(0);
- }
- else {
- xSemaphoreTake(transfer_sem, portMAX_DELAY);
- memcpy(leds, buffer, NUM_LEDS * 3);
- xSemaphoreGive(diplay_sem);
- }
- }
- }
- void sdStart() {
- if (!SD.begin(5,SPI, 80000000)) {
- Serial.println("Card Mount Failed");
- SD_OK = false;
- }
- else
- {
- uint8_t cardType = SD.cardType();
- if (cardType == CARD_NONE) {
- Serial.println("No SD card attached");
- SD_OK = false;
- }
- else
- {
- SD_OK = true;
- }
- }
- myFile = SD.open(getNextFileName()); //to change with your filename
- }
Advertisement
Add Comment
Please, Sign In to add comment