Artnet ws2812 Matrix Controller

    Artnet ws2812 Matrix Controller

    Heute kommt von mir auch mal ein Code den ich im Internet Gefunden habe und ihn hier mal Teilen möchte für all diejenigen die Probleme haben ihre Matrix zum laufen zu bringen.
    Dieses Sketch funktioniert im Artnet über Lan oder w-lan (durch Wlan Router oder switch)
    Dazu wird die Neopixel und Artnet library benötigt.

    C-Quellcode

    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 = 165; // 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 = 2; // 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 universesReceived1[512]; //DMX 1
    23. bool sendFrame = 1;
    24. int previousDataLength = 0;
    25. // Change ip and mac address for your setup
    26. byte ip[] = {192, 168, 178, 46};
    27. byte mac[] = {
    28. 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
    29. };
    30. EthernetClient client;
    31. void setup()
    32. {
    33. Serial.begin(9600);
    34. // this check is only needed on the Leonardo:
    35. while (!Serial) {
    36. ; // wait for serial port to connect. Needed for Leonardo only
    37. }
    38. // start the Ethernet connection:
    39. if (Ethernet.begin(mac) == 0) {
    40. Serial.println("Failed to configure Ethernet using DHCP");
    41. // no point in carrying on, so do nothing forevermore:
    42. for (;;)
    43. ;
    44. }
    45. // print your local IP address:
    46. Serial.print("My IP address: ");
    47. for (byte thisByte = 0; thisByte < 4; thisByte++) {
    48. // print the value of each byte of the IP address:
    49. Serial.print(Ethernet.localIP()[thisByte], DEC);
    50. Serial.print(".");
    51. }
    52. Serial.println();
    53. //Serial.begin(115200);
    54. artnet.begin(mac, ip);
    55. leds.begin();
    56. initTest();
    57. // this will be called for each packet received
    58. artnet.setArtDmxCallback(onDmxFrame);
    59. }
    60. void loop()
    61. {
    62. // we call the read function inside the loop
    63. artnet.read();
    64. }
    65. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
    66. {
    67. sendFrame = 1;
    68. // set brightness of the whole strip
    69. if (universe == 15)
    70. {
    71. leds.setBrightness(data[0]);
    72. leds.show();
    73. }
    74. /*
    75. //____________DMX1______________________________
    76. if ((universe - dmxUniverse1) < 512)
    77. universesReceived1[universe - dmxUniverse1] = 1;
    78. for (int i = 0; i < length; i++)
    79. {
    80. int led = i + (universe - startUniverse) * (previousDataLength / 3);
    81. if (led < numLeds)
    82. leds.setPixelColor(led, data[i], data[i], data[i]);
    83. }
    84. //______________________________________________
    85. // Store which universe has got in
    86. */
    87. if ((universe - startUniverse) < maxUniverses)
    88. universesReceived[universe - startUniverse] = 1;
    89. for (int i = 0 ; i < maxUniverses ; i++)
    90. {
    91. if (universesReceived[i] == 0)
    92. {
    93. Serial.println("Broke");
    94. sendFrame = 0;
    95. break;
    96. }
    97. }
    98. // read universe and put into the right part of the display buffer
    99. for (int i = 0; i < length / 3; i++)
    100. {
    101. int led = i + (universe - startUniverse) * (previousDataLength / 3);
    102. if (led < numLeds)
    103. leds.setPixelColor(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
    104. }
    105. previousDataLength = length;
    106. if (sendFrame)
    107. {
    108. leds.show();
    109. // Reset universeReceived to 0
    110. memset(universesReceived1, 0, 512);
    111. }
    112. }
    113. void initTest()
    114. {
    115. for (int i = 0 ; i < numLeds ; i++)
    116. leds.setPixelColor(i, 127, 0, 0);
    117. leds.show();
    118. delay(500);
    119. for (int i = 0 ; i < numLeds ; i++)
    120. leds.setPixelColor(i, 0, 127, 0);
    121. leds.show();
    122. delay(500);
    123. for (int i = 0 ; i < numLeds ; i++)
    124. leds.setPixelColor(i, 0, 0, 127);
    125. leds.show();
    126. delay(500);
    127. for (int i = 0 ; i < numLeds ; i++)
    128. leds.setPixelColor(i, 0, 0, 0);
    129. leds.show();
    130. }