Here is the code. Any help would be greatly appreciated.
Part of the loop:
Code: Select all
void loop()
{
int packetSize = ARTNETUDP.parsePacket();
if(packetSize)
{
ARTNETUDP.read(DataBuffer, EthernetBufferMax);
int opcode = artNetOpCode(DataBuffer);
if (opcode == ARTNET_ARTDMX)
{
Serial.println("ArtNet Packet Received");
artDMXReceived();
}
}
else
{
packetSize = E131UDP.parsePacket();
if(packetSize)
{
E131UDP.read(DataBuffer, EthernetBufferMax);
int count = checkACNHeaders(DataBuffer, packetSize);
if (count)
{
//Serial.println("E131 Packet Received");
E131Received();
}
}
}
Code: Select all
//checks to see if packet is E1.31 data
int checkACNHeaders(unsigned char* messagein, int messagelength)
{
if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37)
{
int addresscount = messagein[123] * 256 + messagein[124]; // number of values plus start code
return addresscount -1; //Return how many values are in the packet.
}
return 0;
}
void E131Received()
{
if(DataBuffer[114] == 1)
{
Serial.println("Universe 1");
Channel = 1; //reset channel assignment to 1 each time through loop.
for(int i = 0; i < 170; i++) //set values for 170 pixels. Max number per universe.
{
leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
Channel += ChannelWidth; //increase last channel number by channel width
}
}
if(DataBuffer[114] == 2)
{
Serial.println("Universe 2");
Channel = 1; //reset channel assignment to 1 each time through loop.
for(int i = 170; i < 340; i++) //set values for 170 pixels. Max number per universe.
{
leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
Channel += ChannelWidth; //increase last channel number by channel width
}
}
if(DataBuffer[114] == 3)
{
Serial.println("Universe 3");
Channel = 1; //reset channel assignment to 1 each time through loop.
for(int i = 340; i < 510; i++) //set values for 170 pixels. Max number per universe.
{
leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
Channel += ChannelWidth; //increase last channel number by channel width
}
}
if(DataBuffer[114] == 4)
{
Serial.println("Universe 4");
Channel = 1; //reset channel assignment to 1 each time through loop.
for(int i = 510; i < 680; i++) //set values for 170 pixels. Max number per universe.
{
leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
Channel += ChannelWidth; //increase last channel number by channel width
}
}
if(DataBuffer[114] == 5)
{
Serial.println("Universe 5");
Channel = 1; //reset channel assignment to 1 each time through loop.
for(int i = 680; i < 850; i++) //set values for 170 pixels. Max number per universe.
{
leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
Channel += ChannelWidth; //increase last channel number by channel width
}
}
if(DataBuffer[114] == 6)
{
Serial.println("Universe 6");
Channel = 1; //reset channel assignment to 1 each time through loop.
for(int i = 850; i < 1020; i++) //set values for 170 pixels. Max number per universe.
{
leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
Channel += ChannelWidth; //increase last channel number by channel width
}
FastLED.show(); /
}
} //end function