Guest User

Untitled

a guest
May 4th, 2023
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 0 0
  1. #include "FastLED.h"
  2. #include "freertos/queue.h"
  3. #include "freertos/semphr.h"
  4.  
  5. #include "SD.h"
  6. #include "SPI.h"
  7.  
  8. #define NUM_LEDS  5184
  9. #define LEDS_PER_PIN  (NUM_LEDS / 8)
  10. #define QUEUE_SIZE 50
  11.  
  12. #define DELAY_FRAMES 10 //to set up the delay between frames you'll not be doing more than 36fps anyway
  13.  
  14.  
  15.  
  16. CRGB leds[NUM_LEDS];
  17. CRGB buffer[NUM_LEDS];
  18.  
  19. File myFile;
  20.  
  21.  
  22. static xQueueHandle _frame_queue;
  23. static TaskHandle_t _displayFrameTaskhandle;
  24.  
  25. volatile xSemaphoreHandle diplay_sem = NULL;
  26. volatile xSemaphoreHandle transfer_sem = NULL;
  27.  
  28. bool SD_OK = false;
  29.  
  30.  
  31. static void displayframe(void *pvParameters)
  32. {
  33.   for (;;)
  34.   {
  35.     xSemaphoreTake(diplay_sem, portMAX_DELAY);
  36.     FastLED.show();
  37.     xSemaphoreGive(transfer_sem);
  38.   }
  39. }
  40.  
  41.  
  42.  
  43.  
  44. void stripsConfig() {
  45.   FastLED.addLeds<WS2812B, 13, EOrder::GRB>(leds, 0 * LEDS_PER_PIN, LEDS_PER_PIN);
  46.   FastLED.addLeds<WS2812B, 12, EOrder::GRB>(leds, 1 * LEDS_PER_PIN, LEDS_PER_PIN);
  47.   FastLED.addLeds<WS2812B, 14, EOrder::GRB>(leds, 2 * LEDS_PER_PIN, LEDS_PER_PIN);
  48.   FastLED.addLeds<WS2812B, 27, EOrder::GRB>(leds, 3 * LEDS_PER_PIN, LEDS_PER_PIN);
  49.   FastLED.addLeds<WS2812B, 26, EOrder::GRB>(leds, 4 * LEDS_PER_PIN, LEDS_PER_PIN);
  50.   FastLED.addLeds<WS2812B, 25, EOrder::GRB>(leds, 5 * LEDS_PER_PIN, LEDS_PER_PIN);
  51.   FastLED.addLeds<WS2812B, 33, EOrder::GRB>(leds, 6 * LEDS_PER_PIN, LEDS_PER_PIN);
  52.   FastLED.addLeds<WS2812B, 32, EOrder::GRB>(leds, 7 * LEDS_PER_PIN, LEDS_PER_PIN);
  53. }
  54.  
  55.  
  56. void setup() {
  57.   // put your setup code here, to run once:
  58.   Serial.begin(115200);
  59.   stripsConfig();
  60.   sdStart();
  61.   diplay_sem = xSemaphoreCreateBinary();
  62.   transfer_sem  = xSemaphoreCreateBinary();
  63.   xTaskCreateUniversal(displayframe, "displayframe", 4096, NULL, 3, &_displayFrameTaskhandle, 0);
  64.  
  65.   xSemaphoreGive(transfer_sem);
  66. }
  67.  
  68.  
  69. bool readNextFrame(File sdfile) {
  70.   if (sdfile.available() > 0) {
  71.     sdfile.read((uint8_t *)buffer, NUM_LEDS * 3);
  72.     return true;
  73.   }
  74.   else {
  75.     return false;
  76.   }
  77. }
  78.  
  79. void loop() {
  80.   if (SD_OK) {
  81.     if (!readNextFrame(myFile)) {
  82.       myFile.seek(0);
  83.     }
  84.     else {
  85.       xSemaphoreTake(transfer_sem, portMAX_DELAY);
  86.       memcpy(leds, buffer, NUM_LEDS * 3);
  87.       xSemaphoreGive(diplay_sem);
  88.     }
  89.   }
  90. }
  91.  
  92. void sdStart() {
  93.   if (!SD.begin(5,SPI, 80000000)) {
  94.     Serial.println("Card Mount Failed");
  95.     SD_OK = false;
  96.   }
  97.   else
  98.   {
  99.     uint8_t cardType = SD.cardType();
  100.     if (cardType == CARD_NONE) {
  101.       Serial.println("No SD card attached");
  102.       SD_OK = false;
  103.     }
  104.     else
  105.     {
  106.       SD_OK = true;
  107.     }
  108.   }
  109.   myFile = SD.open(getNextFileName()); //to change with your filename
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment