ArtnetNeoPixelESPSync.ino 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <Adafruit_NeoPixel.h>
  8. const char* ssid = "yourssid";
  9. const char* password = "yourpassword";
  10. // Neopixel settings
  11. const int numLeds = 240; // change for your setup
  12. const int channelsPerLed = 3;
  13. const int numberOfChannels = numLeds * channelsPerLed; // 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. int previousDataLength = 0;
  20. byte broadcast[] = {10, 0, 1, 255};
  21. void setup()
  22. {
  23. Serial.begin(115200);
  24. WiFi.begin(ssid, password);
  25. while (WiFi.status() != WL_CONNECTED) {
  26. delay(250);
  27. Serial.print(".");
  28. }
  29. Serial.println("");
  30. Serial.print("Connected to ");
  31. Serial.println(ssid);
  32. Serial.print("IP address: ");
  33. Serial.println(WiFi.localIP());
  34. //Serial.begin(115200);
  35. artnet.begin();
  36. leds.begin();
  37. artnet.setBroadcast(broadcast);
  38. initTest();
  39. // this will be called for each packet received
  40. artnet.setArtDmxCallback(onDmxFrame);
  41. artnet.setArtSyncCallback(onSync);
  42. }
  43. void loop()
  44. {
  45. // we call the read function inside the loop
  46. artnet.read();
  47. }
  48. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
  49. {
  50. // read universe and put into the right part of the display buffer
  51. for (int i = 0; i < length / channelsPerLed; i++)
  52. {
  53. int led = i + (universe - startUniverse) * (previousDataLength / channelsPerLed);
  54. if (led < numLeds) {
  55. if (channelsPerLed == 4)
  56. leds.setPixelColor(led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2], data[i * channelsPerLed + 3]);
  57. if (channelsPerLed == 3)
  58. leds.setPixelColor(led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2]);
  59. }
  60. }
  61. previousDataLength = length;
  62. }
  63. void onSync(IPAddress remoteIP) {
  64. leds.show();
  65. }
  66. void initTest()
  67. {
  68. for (int i = 0 ; i < numLeds ; i++)
  69. leds.setPixelColor(i, 127, 0, 0);
  70. leds.show();
  71. delay(500);
  72. for (int i = 0 ; i < numLeds ; i++)
  73. leds.setPixelColor(i, 0, 127, 0);
  74. leds.show();
  75. delay(500);
  76. for (int i = 0 ; i < numLeds ; i++)
  77. leds.setPixelColor(i, 0, 0, 127);
  78. leds.show();
  79. delay(500);
  80. for (int i = 0 ; i < numLeds ; i++)
  81. leds.setPixelColor(i, 0, 0, 0);
  82. leds.show();
  83. }