Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <NeoPixelBus.h>
- #include <Artnet.h>
- #include <WiFi.h>
- #include <SPI.h>
- #include <ETH.h>
- // Neopixel settings
- const int numLeds1 = 144; // number of leds on pin 2
- const int numLeds2 = 144; // number of leds on pin 3
- const int channelsPerLed = 4; // 4 channels fixed for now
- const int PixelPin1 = 4; // make sure to set this to the correct pin
- const int PixelPin2 = 2; // make sure to set this to the correct pin
- // Calculate the amount of universes needed per pin
- int totalPixelCount = numLeds1 + numLeds2;
- const int numberOfChannels1 = numLeds1 * channelsPerLed; // Total number of channels you want to receive (1 led = 4 channels)
- const int numberOfUniverses1 = (numberOfChannels1 + 512 - 1) / 512;
- const int numberOfChannels2 = numLeds2 * channelsPerLed; // Total number of channels you want to receive (1 led = 4 channels)
- const int numberOfUniverses2 = (numberOfChannels2 + 512 - 1) / 512;
- int totalUniverses = numberOfUniverses1 + numberOfUniverses2;
- // Setup the Neopixelbus pins
- typedef NeoPixelBus<NeoGrbwFeature, NeoEsp32RmtNSk6812Method> MyNeoPixelBus;
- MyNeoPixelBus strips[] = {
- MyNeoPixelBus(numLeds1, PixelPin1, NeoBusChannel_0),
- MyNeoPixelBus(numLeds2, PixelPin2, NeoBusChannel_1)
- };
- // NeoPixelBus<NeoGrbwFeature, NeoEsp32Rmt0Sk6812Method> leds1(numLeds1, PixelPin1);
- // NeoPixelBus<NeoGrbwFeature, NeoEsp32Rmt1Sk6812Method> leds2(numLeds2, PixelPin2);
- RgbwColor red(255, 0, 0, 0);
- RgbwColor green(0, 255, 0, 0);
- RgbwColor blue(0, 0, 255, 0);
- RgbwColor white(0, 0, 0, 255);
- RgbwColor black(0, 0, 0, 0);
- // Ethernet stuff
- char hostname[] = "controller";
- WiFiClient ethclient;
- static bool eth_connected = false;
- void WiFiEvent(WiFiEvent_t event)
- {
- switch (event) {
- case SYSTEM_EVENT_ETH_START:
- Serial.println("ETH Started");
- ETH.setHostname(hostname);
- break;
- case SYSTEM_EVENT_ETH_CONNECTED:
- Serial.println("ETH Connected");
- break;
- case SYSTEM_EVENT_ETH_GOT_IP:
- Serial.print("ETH MAC: ");
- Serial.print(ETH.macAddress());
- Serial.print(", IPv4: ");
- Serial.print(ETH.localIP());
- if (ETH.fullDuplex()) {
- Serial.print(", FULL_DUPLEX");
- }
- Serial.print(", ");
- Serial.print(ETH.linkSpeed());
- Serial.println("Mbps");
- eth_connected = true;
- break;
- case SYSTEM_EVENT_ETH_DISCONNECTED:
- Serial.println("ETH Disconnected");
- eth_connected = false;
- break;
- case SYSTEM_EVENT_ETH_STOP:
- Serial.println("ETH Stopped");
- eth_connected = false;
- break;
- default:
- break;
- }
- }
- // Artnet settings
- Artnet artnet;
- const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
- int previousDataLength = 0;
- bool dmx_frame;
- void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
- {
- // read universe and put into the right part of the display buffer
- if (universe < totalUniverses){
- for (int i = 0; i < length / channelsPerLed; i++)
- {
- int led = i + (universe - startUniverse) * (previousDataLength / channelsPerLed);
- RgbwColor color(data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2], data[i * channelsPerLed + 3]);
- if (led < numLeds1) {
- Serial.println(PixelPin1);
- // Serial.print("pin1 led: ");
- // Serial.println(led);
- // Serial.printf("Led: %i channel1: %i channel2 %i channel3 %i channel4 %i\n", led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2], data[i * channelsPerLed + 3] );
- strips[0].SetPixelColor(led, color);
- }
- else if (led >= numLeds1 && led < (numLeds1 + numLeds2)) {
- Serial.println(PixelPin2);
- // Serial.printf("Led: %i channel1: %i channel2 %i channel3 %i channel4 %i\n", led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2], data[i * channelsPerLed + 3] );
- strips[1].SetPixelColor(led, color);
- }
- }
- }
- else if (universe > totalUniverses) {
- Serial.print("This universe is not configured: ");
- Serial.println(universe);
- }
- dmx_frame = true;
- previousDataLength = length;
- }
- void setup()
- {
- Serial.begin(115200);
- WiFi.onEvent(WiFiEvent);
- ETH.begin();
- artnet.begin();
- strips[0].Begin();
- strips[1].Begin();
- strips[0].ClearTo(black);
- strips[1].ClearTo(black);
- // this will be called for each packet received
- artnet.setArtDmxCallback(onDmxFrame);
- }
- void loop()
- {
- artnet.read();
- if (dmx_frame) {
- Serial.println("dmx_frame");
- strips[0].Show();
- strips[1].Show();
- dmx_frame = false;
- }
- // Debugging channels and universes
- // Serial.print("Pin 1 channel count: ");
- // Serial.print(numberOfChannels1);
- // Serial.print(" - Pin 1 universes count:");
- // Serial.print(numberOfUniverses1);
- // Serial.print(" --- Pin 2 channel count: ");
- // Serial.print(numberOfChannels2);
- // Serial.print(" - Pin 2 universes count:");
- // Serial.println(numberOfUniverses2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement