#include <SPI.h>
#include <ArtNet.h>
#include <Ethernet.h>
#include <OctoWS2811.h>
// OctoWS2811 settings
const int ledsPerStrip = 240; // change for your setup
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
const int ledsPerUniverse = 170;
ArtNetConfig artNetConfig = {
{0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC}, // MAC
{192, 168, 3, 20}, // IP
{255, 255, 255, 0}, // Subnet mask
0x1936, // UDP port
true, // DHCP
0, 0, // Net and subnet
"OctoWS2811 Node", // Short name
"OctoWS2811 Node", // Long name
4, // Number of ports
{ARTNET_TYPE_DMX|ARTNET_TYPE_OUTPUT,ARTNET_TYPE_DMX|ARTNET_TYPE_OUTPUT,ARTNET_TYPE_DMX|ARTNET_TYPE_OUTPUT,ARTNET_TYPE_DMX|ARTNET_TYPE_OUTPUT}, // Port types
{0, 1, 2, 3}, // Input port addresses
{0, 1, 2, 3} // Output port addresses
};
ArtNet artnet = ArtNet(artNetConfig, 530); // 530 is buffer size
void setup()
{
artnet.begin();
leds.begin();
initTest();
}
void loop()
{
// Receive ArtNet package from Ethernet shield
if(artnet.parsePacket()) {
// Read and handle packet
artnet.handleAny();
// Check packet type
if(artnet.getOpCode() == ARTNET_OPCODE_DMX) {
//uint16_t dmxLength = artnet.getDmxLength();
// Get header and dmx data
byte* dmxData = artnet.getDmxData();
uint8_t dmxUniverse = artnet.getDmxPort();
// Do your DMX handling here!!
int j = 0;
for (int i = dmxUniverse * ledsPerUniverse; i < (dmxUniverse + 1) * ledsPerUniverse; i++,j++)
{
leds.setPixel(i, dmxData[j * 3], dmxData[(j * 3) + 1], dmxData[(j * 3) + 2]);
}
leds.show();
}
}
}
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
void initTest()
{
int wait = 500;
colorChange(RED, wait);
colorChange(GREEN, wait);
colorChange(BLUE, wait);
}
void colorChange(int color, int wait)
{
for (int i=0; i < leds.numPixels(); i++) {
leds.setPixel(i, color);
}
leds.show();
delay(wait);
}