Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MODIFIED Glediator Arduino UNO sketch by Jens Andrée
- // 500k bauds with 80 pixels no problem
- // sdcard stream for stand-alone operation.
- #include <DmxSimple.h>
- #include <FastLED.h>
- #include <SPI.h>
- #include <SD.h>
- #define NUM_LEDS 5
- #define DATA_PIN 7
- #define CLOCK_PIN 8
- #define CMD_NEW_DATA 1
- #define BAUD_RATE 500000 //if using Glediator via serial
- File fxdata;
- CRGB leds[NUM_LEDS];
- CRGB currentColor;
- int brightness = 0;
- void setup()
- {
- DmxSimple.usePin(5);
- DmxSimple.maxChannel(21);
- // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); //se doc for different LED strips
- FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- // Serial.begin(BAUD_RATE); // when using Glediator via usb
- Serial.begin(115200);
- for(int y = 0 ; y < NUM_LEDS ; y++)
- {
- leds[y] = CRGB::Black; // set all leds to black during setup
- }
- FastLED.show();
- pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
- digitalWrite(10, HIGH); // workaround for sdcard failed error...
- if (!SD.begin(4))
- {
- Serial.println("sdcard initialization failed!");
- return;
- }
- Serial.println("sdcard initialization done.");
- // test file open
- fxdata = SD.open("TCL_DMX.dat"); // read only
- if (fxdata)
- {
- Serial.println("file open ok");
- fxdata.close();
- }
- }
- void loop()
- {
- fxdata = SD.open("TCL_DMX.dat"); // read only
- if (fxdata)
- {
- Serial.println("file open ok");
- }
- while (fxdata.available())
- {
- // fxdata.readBytes((char*)leds, NUM_LEDS*3);
- currentColor = fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB
- // currentColor = (fxdata.read());
- Serial.println(fxdata);
- sendDMX(1, currentColor); //RGB Strip #, RGB byte from SD .dat file
- FastLED.show();
- delay(500);
- }
- // close the file in order to prevent hanging IO or similar throughout time
- fxdata.close();
- }
- void sendDMX(int theStrip, CRGB & theColor) {
- for(int z=0; z<3; z++) {
- DmxSimple.write((theStrip + z), theColor[z]); //DMX Channel, PWM Value
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement