mazsy78

Vixen

Oct 7th, 2020 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1. /*
  2.  
  3. Vixen Lights 3.x - Arduino Generic Serial for Addressable Pixels
  4.  
  5. Using this code is pretty straight forward, simply hookup your one wire (WS2811 or WS2812) data line to pin 6 of your Arduino
  6. and upload this code.  Make sure you have properly installed the FastLED library from http://fastled.io Once you are done, simply
  7. power your Pixel strips from an external power supply.  Next configure a Generic Serial Controller inside of Vixen Lights 3.x and
  8. add 3 x pixels for the number of channels.  Configure the Generic Serial Controller to use 115200, 8, none, and 1.  Then create
  9. your element and add "Multiple Items (1 x number of pixels).  Finally select your pixel elements and set them as RGB pixels before
  10. patching them to the controler outputs.  You should now be ready to begin testing.
  11.  
  12. For a complete tutorial check out blog.huntgang.com
  13.  
  14. Created   November 8th, 2014
  15. By        Richard Sloan - www.themindfactory.com
  16. And       David Hunt - blog.huntgang.com
  17. Version   1.4
  18.  
  19. */
  20.  
  21.  
  22. // You must download and install the library from http://fastled.io/
  23. #include <FastLED.h>
  24.  
  25. // Sets the maximum number of LEDs that this code will handle to avoid running out of memory
  26. #define NUM_LEDS 180
  27.  
  28. // Sets the pin which is used to connect to the LED pixel strip
  29. #define DATA_PIN 6
  30.  
  31. CRGB leds[NUM_LEDS];
  32.  
  33.  
  34. void setup() {
  35.   // Define the speed of the serial port
  36.   Serial.begin(115200);
  37. }
  38.  
  39. void loop() {
  40.   // Set some counter / temporary storage variables
  41.   int cnt;
  42.   unsigned int num_leds;
  43.   unsigned int d1, d2, d3;
  44.  
  45.   // Begin an endless loop to receive and process serial data
  46.   for(;;) {
  47.     // Set a counter to 0.  This couter keeps track of the pixel colors received.
  48.     cnt = 0;
  49.     //Begin waiting for the header to be received on the serial bus
  50.     //1st character
  51.     while(!Serial.available());
  52.       if(Serial.read() != '>') {
  53.         continue;
  54.         }
  55.     //second character
  56.     while(!Serial.available());
  57.       if(Serial.read() != '>') {
  58.         continue;
  59.         }
  60.     //get the first digit from the serial bus for the number of pixels to be used
  61.     while(!Serial.available());
  62.       d1 = Serial.read();
  63.     //get the second digit from the serial bus for the number of pixels to be used
  64.     while(!Serial.available());
  65.       d2 = Serial.read();
  66.     //get the third digit from the serial bus for the number of pixels to be used
  67.     while(!Serial.available());
  68.       d3 = Serial.read();
  69.     //get the end of the header
  70.     while(!Serial.available());
  71.       if(Serial.read() != '<') {
  72.         continue;
  73.         }
  74.     while(!Serial.available());
  75.       if(Serial.read() != '<') {
  76.         continue;
  77.         }
  78.     // calculate the number of pixels based on the characters provided in the header digits
  79.     num_leds = (d1-'0')*100+(d2-'0')*10+(d3-'0');
  80.     // ensure the number of pixels does not exceed the number allowed
  81.     if(num_leds > NUM_LEDS) {
  82.       continue;
  83.       }
  84.     // Let the FastLED library know how many pixels we will be addressing
  85.     FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, num_leds);
  86.     // Loop through each of the pixels and read the values for each color
  87.     do {
  88.       while(!Serial.available());
  89.         leds[cnt].r = Serial.read();
  90.       while(!Serial.available());
  91.         leds[cnt].g = Serial.read();
  92.       while(!Serial.available());
  93.         leds[cnt++].b = Serial.read();
  94.       }
  95.     while(--num_leds);
  96.     // Tell the FastLED Library it is time to update the strip of pixels
  97.     FastLED.show();
  98.     // WOO HOO... We are all done and are ready to start over again!
  99.     }
  100. }
Add Comment
Please, Sign In to add comment