Jingleby

Untitled

Apr 30th, 2016
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 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 4
  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. pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
  28. digitalWrite(10, HIGH); // workaround for sdcard failed error...
  29.  
  30. FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  31. Serial.begin(115200);
  32. // Serial.begin(BAUD_RATE); // when using Glediator via usb
  33.  
  34. for(int y = 0 ; y < NUM_LEDS ; y++)
  35. {
  36. leds[y] = CRGB::Black; // set all leds to black during setup
  37. }
  38. FastLED.show();
  39.  
  40. if (!SD.begin(4))
  41. {
  42. Serial.println("sdcard initialization failed!");
  43. return;
  44. }
  45. Serial.println("sdcard initialization done.");
  46.  
  47. // test file open
  48. fxdata = SD.open("myanim.dat"); // read only
  49. if (fxdata)
  50. {
  51. Serial.println("file open ok");
  52. fxdata.close();
  53. }
  54. }
  55.  
  56.  
  57. void sendDMX(int theStrip, CRGB & theColor) {
  58. for(int z=0; z<3; z++) {
  59. DmxSimple.write((theStrip + z), theColor[z]); //DMX Channel, PWM Value
  60. }
  61. }
  62.  
  63. void loop()
  64. {
  65. fxdata = SD.open("myanim.dat"); // read only
  66. if (fxdata)
  67. {
  68. Serial.println("file open ok");
  69. }
  70.  
  71. while (fxdata.available())
  72. {
  73. fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB
  74.  
  75. sendDMX(1, leds[0]); //RGB Strip #, RGB byte from SD .dat file
  76. sendDMX(4, leds[1]);
  77. sendDMX(7, leds[2]);
  78. sendDMX(10, leds[3]);
  79. FastLED.show();
  80. delay(50);
  81. }
  82. fxdata.close(); // close the file in order to prevent hanging IO or similar throughout time
  83. }
Add Comment
Please, Sign In to add comment