jasonpodmore

artnet 6 universe v.6

Jun 8th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <Ethernet.h>
  3. #include <EthernetUdp.h>
  4. #include <SPI.h>
  5. #include <FastLED.h>
  6.  
  7. #define bytes_to_short(h,l) ( ((h << 8) & 0xff00) | (l & 0x00FF) );
  8.  
  9.  
  10.  
  11. byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x4C, 0x8C} ; //the mac adress in HEX of ethernet module/shield
  12. byte ip[] = { 192, 168, 1, 10}; // the IP adress of your device, that should be in same universe of the network you are using
  13. unsigned int localPort = 6454; // DO NOT CHANGE artnet UDP port is by default 6454
  14.  
  15.  
  16. //---------------artnet and buffers------------//
  17. const int first_universe_number = 0;//CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as zero.
  18. const int universeSize = 171;//CHANGE FOR YOUR SETUP
  19. const int number_of_channels= universeSize*3;//will be 3*universeSize// dont change//
  20. byte channel_buffer0[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
  21. byte channel_buffer1[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
  22. //byte channel_buffer2[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
  23. //byte channel_buffer3[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
  24. //byte channel_buffer4[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
  25. //byte channel_buffer5[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
  26. byte buff2[2000];// increase buffer for filtered data to cover size of your total array(removed art-net header)
  27. const int MAX_BUFFER_UDP = 768;//leave as is
  28. char packetBuffer[MAX_BUFFER_UDP]; //buffer to store incoming data
  29. short incoming_universe=0; //leave as is (if suspect uni number issues, try changing first_uni number above first.
  30. const int start_address=0; // 0 if you want to read from channel 1
  31. const int art_net_header_size = 17;
  32.  
  33. EthernetUDP Udp;
  34.  
  35.  
  36.  
  37.  
  38. // Make 'leds' an alias for 'channel_buffer'
  39. CRGB* leds0((CRGB*)(channel_buffer0 - start_address));
  40. CRGB* leds1((CRGB*)(channel_buffer1 - start_address));
  41. CRGB* leds2((CRGB*)(channel_buffer2 - start_address));
  42. CRGB* leds3((CRGB*)(channel_buffer3 - start_address));
  43. CRGB* leds4((CRGB*)(channel_buffer4 - start_address));
  44. CRGB* leds5((CRGB*)(channel_buffer5 - start_address));
  45. // Make NUM_LEDS an alias for 'universeSize'
  46. #define NUM_LEDS universeSize
  47.  
  48.  
  49. void setup() {
  50. Serial.begin(115200);
  51. //setup ethernet and udp socket
  52. Ethernet.begin(mac,ip);
  53. Udp.begin(localPort);
  54. delay(250);
  55. Serial.println("end of setup");
  56. Serial.println("waiting for incoming Artnet to start");
  57. //if nothing appears after this, then the loop is not receiving your
  58. //artnet package
  59. FastLED.addLeds<LPD8806, 4, 3, RGB>(leds0, NUM_LEDS);
  60. FastLED.addLeds<LPD8806, 5, 3, RGB>(leds1, NUM_LEDS);
  61. FastLED.addLeds<LPD8806, 6, 3, RGB>(leds2, NUM_LEDS);
  62. FastLED.addLeds<LPD8806, 7, 3, RGB>(leds3, NUM_LEDS);
  63. FastLED.addLeds<LPD8806, 8, 3, RGB>(leds4, NUM_LEDS);
  64. FastLED.addLeds<LPD8806, 9, 3, RGB>(leds5, NUM_LEDS);
  65. }
  66.  
  67. void loop() {
  68. int packetSize = Udp.parsePacket();
  69. //if(packetSize)
  70. //{ Serial.print("Received packet of size ");//all print can be removed if not debugging
  71. // Serial.println(packetSize);
  72.  
  73. Udp.read(packetBuffer,MAX_BUFFER_UDP);
  74. //can comment out serial print if not debugging
  75. //Serial.print(packetBuffer);// all print can be removed if not debugging
  76. //Serial.print(" ");
  77.  
  78. //-------read incoming universe and sequence number and check for data series-------------//
  79. incoming_universe=bytes_to_short(packetBuffer[15],packetBuffer[14])
  80.  
  81. //-----this section can be commented out if not debugging
  82. //Serial.print("universe number = ");
  83. //Serial.print(incoming_universe);
  84. //byte sequence = packetBuffer[12];
  85. //Serial.print(" ");
  86. //Serial.print("sequence n0. = ");
  87. //Serial.println(sequence);
  88. //finshing printing to serial to check packets
  89.  
  90. //read incoming universe and put into relevent buffer
  91.  
  92. if (incoming_universe == 0)
  93. {
  94. for(int i=start_address;i< number_of_channels;i++) {
  95. channel_buffer0[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
  96. }
  97. }
  98. else if (incoming_universe == 1)
  99. {
  100. for(int i=start_address;i< number_of_channels;i++) {
  101. channel_buffer1[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
  102. }
  103. }
  104. else if (incoming_universe == 2)
  105. {
  106. for(int i=start_address;i< number_of_channels;i++) {
  107. channel_buffer2[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
  108. }
  109. }
  110. else if (incoming_universe == 3)
  111. {
  112. for(int i=start_address;i< number_of_channels;i++) {
  113. channel_buffer3[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
  114. }
  115. }
  116. else if (incoming_universe == 4)
  117. {
  118. for(int i=start_address;i< number_of_channels;i++) {
  119. channel_buffer4[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
  120. }
  121. }
  122. else if (incoming_universe == 5)
  123. {
  124. for(int i=start_address;i< number_of_channels;i++) {
  125. channel_buffer5[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
  126. }
  127. }
  128.  
  129.  
  130.  
  131.  
  132. FastLED.show();
  133. //Serial.print("Red");
  134. //Serial.print(" ");
  135. //Serial.print(channel_buffer[0-start_address]);
  136. //Serial.print(" ");
  137. //Serial.print(" ");
  138. //Serial.print("Green");
  139. //Serial.print(" ");
  140. //Serial.print(channel_buffer[1-start_address]);
  141. //Serial.print(" ");
  142. //Serial.print(" ");
  143. //Serial.print("Blue");
  144. //Serial.print(" ");
  145. //Serial.print(channel_buffer[2-start_address]);
  146. //Serial.print(" ");
  147. }
Advertisement
Add Comment
Please, Sign In to add comment