PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 3 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
  31. void setup()
  32. {
  33. //Serial.begin(115200);
  34. artnet.begin(mac, ip);
  35. leds.begin();
  36. initTest();
  37. // this will be called for each packet received
  38. artnet.setArtDmxCallback(onDmxFrame);
  39. }
  40. void loop()
  41. {
  42. // we call the read function inside the loop
  43. artnet.read();
  44. }
  45. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
  46. {
  47. sendFrame = 1;
  48. // Store which universe has got in
  49. if ((universe - startUniverse) < maxUniverses)
  50. universesReceived[universe - startUniverse] = 1;
  51. for (int i = 0 ; i < maxUniverses ; i++)
  52. {
  53. if (universesReceived[i] == 0)
  54. {
  55. sendFrame = 0;
  56. break;
  57. }
  58. }
  59. // read universe and put into the right part of the display buffer
  60. for (int i = 0; i < length / 3; i++)
  61. {
  62. int led = i + (universe - startUniverse) * (previousDataLength / 3);
  63. if (led < numLeds)
  64. leds.setPixel(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  65. }
  66. previousDataLength = length;
  67. if (sendFrame)
  68. {
  69. leds.show();
  70. // Reset universeReceived to 0
  71. memset(universesReceived, 0, maxUniverses);
  72. }
  73. }
  74. void initTest()
  75. {
  76. for (int i = 0 ; i < numLeds ; i++)
  77. leds.setPixel(i, 127, 0, 0);
  78. leds.show();
  79. delay(500);
  80. for (int i = 0 ; i < numLeds ; i++)
  81. leds.setPixel(i, 0, 127, 0);
  82. leds.show();
  83. delay(500);
  84. for (int i = 0 ; i < numLeds ; i++)
  85. leds.setPixel(i, 0, 0, 127);
  86. leds.show();
  87. delay(500);
  88. for (int i = 0 ; i < numLeds ; i++)
  89. leds.setPixel(i, 0, 0, 0);
  90. leds.show();
  91. }