SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This example will receive multiple universes via Artnet and control a strip of ws2811 leds via
  3. Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
  4. This example may be copied under the terms of the MIT license, see the LICENSE file for details
  5. */
  6.  
  7. #include <Artnet.h>
  8. #include <Ethernet.h>
  9. #include <EthernetUdp.h>
  10. #include <SPI.h>
  11. #include <Adafruit_NeoPixel.h>
  12.  
  13. // Neopixel settings
  14. const int numLeds = 160; // change for your setup
  15. const int channelsPerLed = 2;
  16. const int numberOfChannels = numLeds * channelsPerLed; // Total number of channels you want to receive (1 led = 3 channels)
  17. const byte dataPin = 2;
  18. Adafruit_NeoPixel leds = Adafruit_NeoPixel(numLeds, dataPin, NEO_GRB + NEO_KHZ800);
  19.  
  20. // Artnet settings
  21. Artnet artnet;
  22. const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
  23.  
  24. // Check if we got all universes
  25. const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
  26. bool universesReceived[maxUniverses];
  27. bool sendFrame = 1;
  28. int previousDataLength = 0;
  29.  
  30. // Change ip and mac address for your setup
  31. byte ip[] = {10, 10, 12, 199};
  32. byte mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
  33. byte broadcast[] = {255, 255, 255, 255};
  34. void setup()
  35. {
  36.   //Serial.begin(115200);
  37.   artnet.begin(mac, ip);
  38.   leds.begin();
  39.   artnet.setBroadcast(broadcast);
  40.   initTest();
  41.  
  42.   // this will be called for each packet received
  43.   artnet.setArtDmxCallback(onDmxFrame);
  44. }
  45.  
  46. void loop()
  47. {
  48.   // we call the read function inside the loop
  49.   artnet.read();
  50. }
  51.  
  52. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
  53. {
  54.   sendFrame = 1;
  55.   // set brightness of the whole strip
  56.   if (universe == 15)
  57.   {
  58.     leds.setBrightness(data[0]);
  59.     leds.show();
  60.   }
  61.  
  62.   // Store which universe has got in
  63.   if ((universe - startUniverse) < maxUniverses)
  64.     universesReceived[universe - startUniverse] = 1;
  65.  
  66.   for (int i = 0 ; i < maxUniverses ; i++)
  67.   {
  68.     if (universesReceived[i] == 0)
  69.     {
  70.       //Serial.println("Broke");
  71.       sendFrame = 0;
  72.       break;
  73.     }
  74.   }
  75.  
  76.   // read universe and put into the right part of the display buffer
  77.   for (int i = 0; i < length / channelsPerLed; i++)
  78.   {
  79.     int led = i + (universe - startUniverse) * (previousDataLength / channelsPerLed);
  80.     if (led < numLeds) {
  81.       if (channelsPerLed == 4)
  82.         leds.setPixelColor(led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2], data[i * channelsPerLed + 3]);
  83.       if (channelsPerLed == 3)
  84.         leds.setPixelColor(led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2]);
  85.     }
  86.   }
  87.   previousDataLength = length;
  88.  
  89.   if (sendFrame)
  90.   {
  91.     leds.show();
  92.     // Reset universeReceived to 0
  93.     memset(universesReceived, 0, maxUniverses);
  94.   }
  95. }
  96.  
  97. void initTest()
  98. {
  99.   for (int i = 0 ; i < numLeds ; i++)
  100.     leds.setPixelColor(i, 127, 0, 0);
  101.   leds.show();
  102.   delay(500);
  103.   for (int i = 0 ; i < numLeds ; i++)
  104.     leds.setPixelColor(i, 0, 127, 0);
  105.   leds.show();
  106.   delay(500);
  107.   for (int i = 0 ; i < numLeds ; i++)
  108.     leds.setPixelColor(i, 0, 0, 127);
  109.   leds.show();
  110.   delay(500);
  111.   for (int i = 0 ; i < numLeds ; i++)
  112.     leds.setPixelColor(i, 0, 0, 0);
  113.   leds.show();
  114. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top