Advertisement
Guest User

Reading SD Card and displaying via Chainable RGB + DMX

a guest
Apr 27th, 2016
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // MODIFIED Glediator Arduino UNO sketch by Jens Andrée
  2. // 500k bauds with 80 pixels no problem
  3. // sdcard stream for stand-alone operation.
  4.  
  5. #include <DmxSimple.h>
  6. #include <FastLED.h>
  7. #include <SPI.h>
  8. #include <SD.h>
  9.  
  10. #define NUM_LEDS 5
  11. #define DATA_PIN 7
  12. #define CLOCK_PIN 8
  13. #define CMD_NEW_DATA 1
  14. #define BAUD_RATE 500000 //if using Glediator via serial
  15.  
  16. File fxdata;
  17. CRGB leds[NUM_LEDS];
  18. CRGB currentColor;
  19.  
  20. int brightness = 0;
  21.  
  22. void setup()
  23. {
  24. DmxSimple.usePin(5);
  25. DmxSimple.maxChannel(21);
  26.  
  27. // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); //se doc for different LED strips
  28. FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  29. // Serial.begin(BAUD_RATE); // when using Glediator via usb
  30. Serial.begin(115200);
  31.  
  32. for(int y = 0 ; y < NUM_LEDS ; y++)
  33. {
  34. leds[y] = CRGB::Black; // set all leds to black during setup
  35. }
  36. FastLED.show();
  37.  
  38. pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
  39. digitalWrite(10, HIGH); // workaround for sdcard failed error...
  40.  
  41. if (!SD.begin(4))
  42. {
  43. Serial.println("sdcard initialization failed!");
  44. return;
  45. }
  46. Serial.println("sdcard initialization done.");
  47.  
  48. // test file open
  49. fxdata = SD.open("TCL_DMX.dat"); // read only
  50. if (fxdata)
  51. {
  52. Serial.println("file open ok");
  53. fxdata.close();
  54. }
  55. }
  56.  
  57. void loop()
  58. {
  59. fxdata = SD.open("TCL_DMX.dat"); // read only
  60. if (fxdata)
  61. {
  62. Serial.println("file open ok");
  63. }
  64.  
  65. while (fxdata.available())
  66. {
  67. // fxdata.readBytes((char*)leds, NUM_LEDS*3);
  68. currentColor = fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB
  69. // currentColor = (fxdata.read());
  70.  
  71. Serial.println(fxdata);
  72.  
  73. sendDMX(1, currentColor); //RGB Strip #, RGB byte from SD .dat file
  74. FastLED.show();
  75. delay(500);
  76. }
  77. // close the file in order to prevent hanging IO or similar throughout time
  78. fxdata.close();
  79. }
  80.  
  81. void sendDMX(int theStrip, CRGB & theColor) {
  82. for(int z=0; z<3; z++) {
  83. DmxSimple.write((theStrip + z), theColor[z]); //DMX Channel, PWM Value
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement