ArtnetOctoWS2811.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. This example will receive multiple universes via Artnet and control a strip of ws2811 leds via
  3. Paul Stoffregen's excellent OctoWS2811 library: https://www.pjrc.com/teensy/td_libs_OctoWS2811.html
  4. This example may be copied under the terms of the MIT license, see the LICENSE file for details
  5. */
  6. #include <Artnet.h>
  7. #include <Ethernet.h>
  8. #include <EthernetUdp.h>
  9. #include <SPI.h>
  10. #include <OctoWS2811.h>
  11. // OctoWS2811 settings
  12. const int ledsPerStrip = 240; // change for your setup
  13. const byte numStrips= 2; // change for your setup
  14. const int numLeds = ledsPerStrip * numStrips;
  15. const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
  16. DMAMEM int displayMemory[ledsPerStrip*6];
  17. int drawingMemory[ledsPerStrip*6];
  18. const int config = WS2811_GRB | WS2811_800kHz;
  19. OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
  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. // Check if we got all universes
  24. const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
  25. bool universesReceived[maxUniverses];
  26. bool sendFrame = 1;
  27. int previousDataLength = 0;
  28. // Change ip and mac address for your setup
  29. byte ip[] = {192, 168, 2, 2};
  30. byte broadcast[] = {192, 168, 2, 255};
  31. byte mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
  32. void setup()
  33. {
  34. //Serial.begin(115200);
  35. artnet.setBroadcast(broadcast);
  36. artnet.begin(mac, ip);
  37. leds.begin();
  38. initTest();
  39. // this will be called for each packet received
  40. artnet.setArtDmxCallback(onDmxFrame);
  41. }
  42. void loop()
  43. {
  44. // we call the read function inside the loop
  45. artnet.read();
  46. }
  47. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
  48. {
  49. sendFrame = 1;
  50. // Store which universe has got in
  51. if ((universe - startUniverse) < maxUniverses)
  52. universesReceived[universe - startUniverse] = 1;
  53. for (int i = 0 ; i < maxUniverses ; i++)
  54. {
  55. if (universesReceived[i] == 0)
  56. {
  57. sendFrame = 0;
  58. break;
  59. }
  60. }
  61. // read universe and put into the right part of the display buffer
  62. for (int i = 0; i < length / 3; i++)
  63. {
  64. int led = i + (universe - startUniverse) * (previousDataLength / 3);
  65. if (led < numLeds)
  66. leds.setPixel(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  67. }
  68. previousDataLength = length;
  69. if (sendFrame)
  70. {
  71. leds.show();
  72. // Reset universeReceived to 0
  73. memset(universesReceived, 0, maxUniverses);
  74. }
  75. }
  76. void initTest()
  77. {
  78. for (int i = 0 ; i < numLeds ; i++)
  79. leds.setPixel(i, 127, 0, 0);
  80. leds.show();
  81. delay(500);
  82. for (int i = 0 ; i < numLeds ; i++)
  83. leds.setPixel(i, 0, 127, 0);
  84. leds.show();
  85. delay(500);
  86. for (int i = 0 ; i < numLeds ; i++)
  87. leds.setPixel(i, 0, 0, 127);
  88. leds.show();
  89. delay(500);
  90. for (int i = 0 ; i < numLeds ; i++)
  91. leds.setPixel(i, 0, 0, 0);
  92. leds.show();
  93. }