PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

115 lines
3.3KB

  1. // Receive multiple universes via Artnet and control a strip of ws2811 leds via OctoWS2811
  2. //
  3. // This example may be copied under the terms of the MIT license, see the LICENSE file for details
  4. // https://github.com/natcl/Artnet
  5. //
  6. // http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811?p=55589&viewfull=1#post55589
  7. #include <Artnet.h>
  8. #include <Ethernet.h>
  9. #include <EthernetUdp.h>
  10. #include <SPI.h>
  11. #include <OctoWS2811.h>
  12. // Ideas for improving performance with WIZ820io / WIZ850io Ethernet:
  13. // https://forum.pjrc.com/threads/45760-E1-31-sACN-Ethernet-DMX-Performance-help-6-Universe-Limit-improvements
  14. // OctoWS2811 settings
  15. const int ledsPerStrip = 492; // change for your setup
  16. const byte numStrips= 1; // change for your setup
  17. DMAMEM int displayMemory[ledsPerStrip*6];
  18. int drawingMemory[ledsPerStrip*6];
  19. const int config = WS2811_GRB | WS2811_800kHz;
  20. OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
  21. // Artnet settings
  22. Artnet artnet;
  23. const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as zero.
  24. const int numberOfChannels = ledsPerStrip * numStrips * 3; // Total number of channels you want to receive (1 led = 3 channels)
  25. byte channelBuffer[numberOfChannels]; // Combined universes into a single array
  26. // Check if we got all universes
  27. const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
  28. bool universesReceived[maxUniverses];
  29. bool sendFrame = 1;
  30. // Change ip and mac address for your setup
  31. byte ip[] = {192, 168, 2, 2};
  32. byte mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
  33. void setup()
  34. {
  35. Serial.begin(115200);
  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)
  48. {
  49. sendFrame = 1;
  50. // Store which universe has got in
  51. if (universe < maxUniverses)
  52. universesReceived[universe] = 1;
  53. for (int i = 0 ; i < maxUniverses ; i++)
  54. {
  55. if (universesReceived[i] == 0)
  56. {
  57. //Serial.println("Broke");
  58. sendFrame = 0;
  59. break;
  60. }
  61. }
  62. // read universe and put into the right part of the display buffer
  63. for (int i = 0 ; i < length ; i++)
  64. {
  65. int bufferIndex = i + ((universe - startUniverse) * length);
  66. if (bufferIndex < numberOfChannels) // to verify
  67. channelBuffer[bufferIndex] = byte(data[i]);
  68. }
  69. // send to leds
  70. for (int i = 0; i < ledsPerStrip * numStrips; i++)
  71. {
  72. leds.setPixel(i, channelBuffer[(i) * 3], channelBuffer[(i * 3) + 1], channelBuffer[(i * 3) + 2]);
  73. }
  74. if (sendFrame)
  75. {
  76. leds.show();
  77. // Reset universeReceived to 0
  78. memset(universesReceived, 0, maxUniverses);
  79. }
  80. }
  81. void initTest()
  82. {
  83. for (int i = 0 ; i < ledsPerStrip * numStrips ; i++)
  84. leds.setPixel(i, 127, 0, 0);
  85. leds.show();
  86. delay(500);
  87. for (int i = 0 ; i < ledsPerStrip * numStrips ; i++)
  88. leds.setPixel(i, 0, 127, 0);
  89. leds.show();
  90. delay(500);
  91. for (int i = 0 ; i < ledsPerStrip * numStrips ; i++)
  92. leds.setPixel(i, 0, 0, 127);
  93. leds.show();
  94. delay(500);
  95. for (int i = 0 ; i < ledsPerStrip * numStrips ; i++)
  96. leds.setPixel(i, 0, 0, 0);
  97. leds.show();
  98. }