Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- // enter desired universe and subnet (sACN first universe is 1)
- #define DMX_SUBNET 0
- #define DMX_UNIVERSE 1
- #define E131_BUFFER_MAX 638
- #define E131_ADDRESS_OFFSET 126
- // buffers for receiving and sending data
- unsigned char E131Buffer[E131_BUFFER_MAX]; //buffer to hold incoming packet,
- //Pixel Setup
- #define NUM_LEDS 50 //total number of pixels
- #define DATA_PIN 51 //pin pixels are connected to
- CRGB leds[NUM_LEDS]; //pixel array
- void setup()
- {
- Serial.begin(115200); //initialize serial for USB serial monitor
- Serial1.begin(115200); //initialize serial input from ESP8266
- FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); //initialize pixels
- Serial.println("Setup Complete");
- } //end setup
- void E131Received(unsigned char* pbuff, int count)
- {
- if ( pbuff[113] == DMX_SUBNET )
- {
- if ( pbuff[114] == DMX_UNIVERSE )
- {
- if ( pbuff[E131_ADDRESS_OFFSET-1] == 0 ) //start code must be 0
- {
- leds[0].setRGB(pbuff[127],pbuff[128],pbuff[129]); //set pixel values
- Serial.println(pbuff[126]); //print value of byte 126 which is DMX channel 1
- }
- }
- }
- FastLED.show(); //output to pixels
- }
- //checks to see if packet is E1.31 data
- int checkE131Headers(unsigned char* messagein, int messagelength)
- {
- Serial.print("Byte 1:");
- Serial.println(messagein[1],HEX);
- Serial.print("Byte 4:");
- Serial.println(messagein[4],HEX);
- Serial.print("Byte 12:");
- Serial.println(messagein[12],HEX);
- if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37)
- {
- int ChannelCount = messagein[123] * 256 + messagein[124]; // number of values plus start code
- return ChannelCount -1; //Return how many values are in the packet.
- }
- return 0;
- }
- void loop()
- {
- if (Serial1.available() > 0)
- {
- int packetSize = Serial1.readBytes(E131Buffer,E131_BUFFER_MAX); //read data into buffer and output size. Size should be 638 bytes.
- if(packetSize) //if data has been received
- {
- int TotalChannels = checkE131Headers(E131Buffer, packetSize); //pass data to see if it is E1.31
- if (TotalChannels) //if data comes back as E1.31
- {
- Serial.println("E1.31 Packet Received");
- E131Received(E131Buffer, TotalChannels); //process data function
- }
- }
- }
- } //end loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement