Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- #include <SPI.h>
- #include <FastLED.h>
- #define bytes_to_short(h,l) ( ((h << 8) & 0xff00) | (l & 0x00FF) );
- byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x4C, 0x8C} ; //the mac adress in HEX of ethernet module/shield
- byte ip[] = { 192, 168, 1, 10}; // the IP adress of your device, that should be in same universe of the network you are using
- unsigned int localPort = 6454; // DO NOT CHANGE artnet UDP port is by default 6454
- //---------------artnet and buffers------------//
- const int first_universe_number = 0;//CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as zero.
- const int universeSize = 171;//CHANGE FOR YOUR SETUP
- const int number_of_channels= universeSize*3;//will be 3*universeSize// dont change//
- byte channel_buffer0[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
- byte channel_buffer1[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
- //byte channel_buffer2[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
- //byte channel_buffer3[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
- //byte channel_buffer4[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
- //byte channel_buffer5[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
- byte buff2[2000];// increase buffer for filtered data to cover size of your total array(removed art-net header)
- const int MAX_BUFFER_UDP = 768;//leave as is
- char packetBuffer[MAX_BUFFER_UDP]; //buffer to store incoming data
- short incoming_universe=0; //leave as is (if suspect uni number issues, try changing first_uni number above first.
- const int start_address=0; // 0 if you want to read from channel 1
- const int art_net_header_size = 17;
- EthernetUDP Udp;
- // Make 'leds' an alias for 'channel_buffer'
- CRGB* leds0((CRGB*)(channel_buffer0 - start_address));
- CRGB* leds1((CRGB*)(channel_buffer1 - start_address));
- CRGB* leds2((CRGB*)(channel_buffer2 - start_address));
- CRGB* leds3((CRGB*)(channel_buffer3 - start_address));
- CRGB* leds4((CRGB*)(channel_buffer4 - start_address));
- CRGB* leds5((CRGB*)(channel_buffer5 - start_address));
- // Make NUM_LEDS an alias for 'universeSize'
- #define NUM_LEDS universeSize
- void setup() {
- Serial.begin(115200);
- //setup ethernet and udp socket
- Ethernet.begin(mac,ip);
- Udp.begin(localPort);
- delay(250);
- Serial.println("end of setup");
- Serial.println("waiting for incoming Artnet to start");
- //if nothing appears after this, then the loop is not receiving your
- //artnet package
- FastLED.addLeds<LPD8806, 4, 3, RGB>(leds0, NUM_LEDS);
- FastLED.addLeds<LPD8806, 5, 3, RGB>(leds1, NUM_LEDS);
- FastLED.addLeds<LPD8806, 6, 3, RGB>(leds2, NUM_LEDS);
- FastLED.addLeds<LPD8806, 7, 3, RGB>(leds3, NUM_LEDS);
- FastLED.addLeds<LPD8806, 8, 3, RGB>(leds4, NUM_LEDS);
- FastLED.addLeds<LPD8806, 9, 3, RGB>(leds5, NUM_LEDS);
- }
- void loop() {
- int packetSize = Udp.parsePacket();
- //if(packetSize)
- //{ Serial.print("Received packet of size ");//all print can be removed if not debugging
- // Serial.println(packetSize);
- Udp.read(packetBuffer,MAX_BUFFER_UDP);
- //can comment out serial print if not debugging
- //Serial.print(packetBuffer);// all print can be removed if not debugging
- //Serial.print(" ");
- //-------read incoming universe and sequence number and check for data series-------------//
- incoming_universe=bytes_to_short(packetBuffer[15],packetBuffer[14])
- //-----this section can be commented out if not debugging
- //Serial.print("universe number = ");
- //Serial.print(incoming_universe);
- //byte sequence = packetBuffer[12];
- //Serial.print(" ");
- //Serial.print("sequence n0. = ");
- //Serial.println(sequence);
- //finshing printing to serial to check packets
- //read incoming universe and put into relevent buffer
- if (incoming_universe == 0)
- {
- for(int i=start_address;i< number_of_channels;i++) {
- channel_buffer0[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
- }
- }
- else if (incoming_universe == 1)
- {
- for(int i=start_address;i< number_of_channels;i++) {
- channel_buffer1[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
- }
- }
- else if (incoming_universe == 2)
- {
- for(int i=start_address;i< number_of_channels;i++) {
- channel_buffer2[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
- }
- }
- else if (incoming_universe == 3)
- {
- for(int i=start_address;i< number_of_channels;i++) {
- channel_buffer3[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
- }
- }
- else if (incoming_universe == 4)
- {
- for(int i=start_address;i< number_of_channels;i++) {
- channel_buffer4[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
- }
- }
- else if (incoming_universe == 5)
- {
- for(int i=start_address;i< number_of_channels;i++) {
- channel_buffer5[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
- }
- }
- FastLED.show();
- //Serial.print("Red");
- //Serial.print(" ");
- //Serial.print(channel_buffer[0-start_address]);
- //Serial.print(" ");
- //Serial.print(" ");
- //Serial.print("Green");
- //Serial.print(" ");
- //Serial.print(channel_buffer[1-start_address]);
- //Serial.print(" ");
- //Serial.print(" ");
- //Serial.print("Blue");
- //Serial.print(" ");
- //Serial.print(channel_buffer[2-start_address]);
- //Serial.print(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment