Guest User

ArtNetReceiveFastLED

a guest
Dec 3rd, 2014
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <ArtNet.h>
  4. #include "FastLED.h"
  5.  
  6.  
  7. #define NUM_LEDS 50
  8. // Data pin that led data will be written out over
  9. #define DATA_PIN 5
  10. // This is an array of leds.  One item for each led in your strip.
  11. CRGB leds[NUM_LEDS];
  12.  
  13. // Default Configuration
  14. ArtNetConfig config = {
  15.   {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}, // MAC
  16.   {192, 168, 1, 177},                     // IP
  17.   {255, 255, 255, 0},                   // Subnet mask
  18.   0x1936,                               // UDP port
  19.   false,                                 // DHCP
  20.   0, 0,                                 // Net and subnet
  21.   "OpenPixelNode",                      // Short name
  22.   "Billy's Test Node v4", // Long name
  23.   1,                                    // Number of ports
  24.   {ARTNET_TYPE_DMX|ARTNET_TYPE_OUTPUT}, // Port types
  25.   {0},                         // Input port addresses
  26.   {0}                          // Output port addresses
  27. };
  28.  
  29. // Defaults
  30. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  31. IPAddress ip(192,168,1,177);
  32.  
  33. // ArtNet class instance
  34. ArtNet artnet = ArtNet(config, 530);
  35.  
  36.  
  37. void setup() {
  38.  
  39.   //SPI.setClockDivider(SPI_CLOCK_DIV2);
  40.   // Initialize Ethernet shield
  41.   Ethernet.begin(mac, ip);
  42.  
  43.   uint16_t sizes[4] = {8192,0,0,0}; // 8 Kb memory to the first socket
  44.   W5100.setRXMemorySizes(sizes);
  45.   W5100.setTXMemorySizes(sizes);
  46.  
  47.   FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  48.  
  49.   // Initialize ArtNet handler
  50.   artnet.begin(); // Start ArtNet handling
  51. }
  52.  
  53. void loop() {
  54.  
  55.   // Receive ArtNet package from Ethernet shield
  56.   if(artnet.parsePacket()) {
  57.    
  58.     // Read and handle packet
  59.     artnet.handleAny();
  60.  
  61.     // Check packet type
  62.     if(artnet.getOpCode() == ARTNET_OPCODE_DMX) {
  63.  
  64.       // Get header and dmx data
  65.       byte* dmx = artnet.getDmxData();
  66.       byte port = artnet.getDmxPort();
  67.       int dmx_length = artnet.getDmxLength();
  68.  
  69.       // Do your DMX handling here!!
  70.       memcpy((CRGB*)leds, dmx, dmx_length / 3);
  71.       FastLED.show();
  72.      
  73.     }
  74.   }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment