PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

109 linhas
2.8KB

  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. #include <Artnet.h>
  7. #include <Ethernet.h>
  8. #include <EthernetUdp.h>
  9. #include <SPI.h>
  10. #include <Adafruit_NeoPixel.h>
  11. // Neopixel settings
  12. const int numLeds = 240; // change for your setup
  13. const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
  14. const byte dataPin = 2;
  15. Adafruit_NeoPixel leds = Adafruit_NeoPixel(numLeds, dataPin, NEO_GRB + NEO_KHZ800);
  16. // Artnet settings
  17. Artnet artnet;
  18. const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
  19. // Check if we got all universes
  20. const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
  21. bool universesReceived[maxUniverses];
  22. bool sendFrame = 1;
  23. int previousDataLength = 0;
  24. // Change ip and mac address for your setup
  25. byte ip[] = {192, 168, 2, 2};
  26. byte mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
  27. void setup()
  28. {
  29. //Serial.begin(115200);
  30. artnet.begin(mac, ip);
  31. leds.begin();
  32. initTest();
  33. // this will be called for each packet received
  34. artnet.setArtDmxCallback(onDmxFrame);
  35. }
  36. void loop()
  37. {
  38. // we call the read function inside the loop
  39. artnet.read();
  40. }
  41. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
  42. {
  43. sendFrame = 1;
  44. // set brightness of the whole strip
  45. if (universe == 15)
  46. {
  47. leds.setBrightness(data[0]);
  48. leds.show();
  49. }
  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. //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 / 3; i++)
  64. {
  65. int led = i + (universe - startUniverse) * (previousDataLength / 3);
  66. if (led < numLeds)
  67. leds.setPixelColor(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  68. }
  69. previousDataLength = length;
  70. if (sendFrame)
  71. {
  72. leds.show();
  73. // Reset universeReceived to 0
  74. memset(universesReceived, 0, maxUniverses);
  75. }
  76. }
  77. void initTest()
  78. {
  79. for (int i = 0 ; i < numLeds ; i++)
  80. leds.setPixelColor(i, 127, 0, 0);
  81. leds.show();
  82. delay(500);
  83. for (int i = 0 ; i < numLeds ; i++)
  84. leds.setPixelColor(i, 0, 127, 0);
  85. leds.show();
  86. delay(500);
  87. for (int i = 0 ; i < numLeds ; i++)
  88. leds.setPixelColor(i, 0, 0, 127);
  89. leds.show();
  90. delay(500);
  91. for (int i = 0 ; i < numLeds ; i++)
  92. leds.setPixelColor(i, 0, 0, 0);
  93. leds.show();
  94. }