Created
January 22, 2019 22:37
-
-
Save premek/dbcddab9a496561561789b57a91e0a84 to your computer and use it in GitHub Desktop.
DMX USB, FastLED RGB LED stripe, OP-Z
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
#include "DMXUSB.h" | |
#include <FastLED.h> | |
SoftwareSerial mySerial(10, 11); // RX, TX | |
#define LED_PIN LED_BUILTIN | |
#define DMXUSB_BAUDRATE 115200 | |
#define NUM_LEDS 16 | |
#define DATA_PIN 3 | |
CRGB leds[NUM_LEDS]; | |
void myDMXCallback(int universe, char buffer[512]) { | |
// Serial.println("msg"); | |
// Serial.println(universe); | |
digitalWrite(LED_PIN, LOW); | |
leds[0] = CRGB::Black; | |
for (int index = 0; index < 512; index++) { | |
int value = buffer[index]; // DMX value 0 to 255 | |
if (value != 0) { | |
// Serial.print(index); | |
// Serial.print("="); | |
// Serial.println(value); | |
} | |
int LEDchannel = index; // Find the LED number; can't fit a 3-channel fixture on the remaining two channels | |
if (LEDchannel <= (NUM_LEDS * 3) - 1) { // If DMX channel (LEDchannel starts at 0) is in range of LEDs (3 channels per LED for RGB) | |
int colorChannel = LEDchannel % 3; // Find the color channel of the LED addressed | |
int ledID = (LEDchannel - colorChannel) / 3; // Find the FastLED index of the LED addressed | |
if (colorChannel == 2) leds[ledID].r = value / 30; // If the channel is red, write the red value of the LED | |
if (colorChannel == 1) leds[ledID].g = value / 30; // If the channel is green, write the red value of the LED | |
if (colorChannel == 0) leds[ledID].b = value / 30; // If the channel is blue, write the blue value of the LED | |
} | |
if (universe == 0 && index < 3 && value != 0) { | |
digitalWrite(LED_PIN, HIGH); | |
} | |
} | |
FastLED.show(); // Display the frame after processing all channels | |
} | |
DMXUSB myDMXUsb(mySerial, DMXUSB_BAUDRATE, 0, myDMXCallback); | |
void setup() { | |
//Serial.begin(115200); | |
mySerial.begin(DMXUSB_BAUDRATE); | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // todo wrong colors? | |
pinMode(LED_PIN, OUTPUT); | |
digitalWrite(LED_PIN, HIGH); delay(100); digitalWrite(LED_PIN, LOW); delay(100); | |
digitalWrite(LED_PIN, HIGH); delay(100); digitalWrite(LED_PIN, LOW); delay(100); | |
leds[0] = CRGB::Red; FastLED.show(); delay(100); leds[0] = CRGB::Black; FastLED.show(); | |
} | |
void loop() { | |
myDMXUsb.listen(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment