Advertisement
Guest User

Beambox Vixen Controlling Code

a guest
May 29th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.86 KB | None | 0 0
  1.  /*
  2.  Beambox - The Tower that Glows to Your Commands
  3.  http://www.instructables.com/id/BeamBox-A-tower-that-glows-to-your-commands/
  4.  By PerfectPixel
  5.  Code by JDC928 (source here: http://doityourselfchristmas.com/forums/showthread.php?31079-Arduino-code-for-driving-RGB-Addressable-pixels-from-Vixen )
  6.  Edited by PerfectPixel
  7.  Requires Adafruits NEOPIXEL library instead of the FastLED library
  8.  Neopixel Library Available Here:
  9.  https://github.com/adafruit/Adafruit_NeoPixel
  10.  
  11.  To Get Started Download Vixen ( http://www.vixenlights.com/ )
  12.  and follow the instructions below          
  13.  */
  14.  /* VIXEN Setup:
  15.  * In Vixen display setup...
  16.  *    - Add an element group containing one element for each pixel attached to arduino
  17.  *    - Configure the 'Color Handling'  as "They can be any color: Full RGB"
  18.  *    - Add a "Generic Serial Controller"
  19.  *    - Name it what you want (Although... Jdc928IsAwesome is great controller name)
  20.  *    - Set the channel count to 3x the number of Pixels you have
  21.  *    - Save, then configure these options
  22.  *    - Com Port: choose the correct port for your arduino's serial
  23.  *    - Baud Rate: 115200 (or whatever you changed it to below)
  24.  *    - Click OK
  25.  *    - Check the box "Send a text header"
  26.  *    - Type "VIXStart" in the header text box
  27.  *    - Click "OK"
  28.  *
  29.  *    - Click and highlight the newly added Element in the elements list
  30.  *    - Click and highlight the newly created controller
  31.  *    - Your "Total Patch Points" and "Output" counts should match
  32.  *    - Click "Patch Elements to Controllers"
  33.  *    - Click OK and you should be ready to go
  34.  *
  35.  *
  36.  *    You should now be able open a Sequence
  37.       add some effects to the new channels
  38.       and see the strips responding accordingly
  39.  
  40.  */
  41.  
  42.  
  43.  
  44. /**
  45.  * Pixel Strip Setup
  46.  *    Strips setups vary but generally as follows
  47.  *    - If your using a large number of strips you will
  48.  *      probably want to power them externally.
  49.  *      
  50.  *    - Connect external V+ to strip Vin
  51.  *    - Connect external Gnd to strip Gnd
  52.  *    - Connect external Gnd to Arduino Gnd
  53.  *    - Connect Strip Data to proper pin on Arduino
  54.  *    - Connect Strip DataClock to proper pin on Arduino if not using ws2812
  55.  */
  56.  
  57.  
  58.  
  59. #include <Adafruit_NeoPixel.h>    //  This is the Neo-Pixel library (ws2812)
  60.                                   //  Change to the library for your pixel types
  61.                                   //  Suggest using a library created by Adafruit
  62.                                   //  so the function names will be the same                              
  63.                                  
  64.                                  
  65.                                  
  66. #define DPIN 9                    //  Change this to the pin# connected to your pixels DataIn
  67.                                   //  Will probably need to define a ClockPin for other pixel
  68.  
  69.  
  70. int   PixelCount = 7;             //  Set this to the number of Pixels connected
  71.  
  72. int   bugLevel  = 0;              //  This is just a way I manage turning debugging over serial on/off
  73.  
  74.  
  75.  
  76. /*  Sets up the NeoPixel Strip object
  77.  Replace with proper Object initiation for your pixel types */
  78. Adafruit_NeoPixel strip = Adafruit_NeoPixel(PixelCount, DPIN, NEO_RGB + NEO_KHZ800);  
  79.  
  80.  
  81.  
  82. void setup()
  83. {
  84.   delay(100);                    //  A delay for a reason I can't remember. I can live with one in the setup.  
  85.   strip.begin();                 //  Get strip started
  86.   strip.show();                  //  Initialize all pixels to 'off'
  87.  
  88.   Serial.begin(115200);          //  Start the Serial communication
  89.  
  90.  
  91. }
  92.  
  93.  
  94. void loop()
  95. {                                       // START LOOP
  96.  
  97.     if (Serial.available()>2)             // Wait for a few bytes to be recieved
  98.   {
  99.  
  100.     waitForVixenHeader();               // Header check function
  101.  
  102.    
  103.     for (int pixCount=0; pixCount<PixelCount;pixCount++)       // Do this for as many Pixels defined in PixelCount
  104.     {
  105.       int RGB[3];                             // Create array to hold this pixels RGB value                  
  106.       for (int color = 0;color<3;color++)     // For the next 3 incoming bytes
  107.       {                      
  108.         while (Serial.available() < 1)        // Wait for bytes to be received
  109.         {
  110.           delay(10);
  111.         }
  112.         RGB[color] = Serial.read();           // Save this byte to the correct RGB value
  113.       }                                       // Repeat until bytes for this pixels RGB value have been recieved
  114.  
  115.       strip.setPixelColor(pixCount,RGB[0],RGB[1],RGB[2]);  //Set this pixels new color
  116.      
  117.     }                                         // Repeat untill all pixels have had new RGB value set
  118.     strip.show();                             // Update the strip and show with new color                            
  119.   }                                           // YAY! DO IT AGAIN!
  120. }                                              // END OF LOOP
  121.  
  122.  
  123.  
  124. /**
  125.  *  FUNC    bugit           [manages printing of debugging based on debugging level]
  126.  *  @param  String  bugstr  [string to be be printed]
  127.  *  @param  int     blevel  [the level at which this debugging should be ignored]
  128.  *    
  129. */
  130.  
  131.  
  132.  
  133.  
  134. /**
  135.  * I 'borrowed' snippets of this waitForVixenHeader() function from some code I found online
  136.  * Can't find the originator now but thank you. It works well.  
  137.  *
  138.  */
  139. void waitForVixenHeader()
  140. {
  141.  
  142.     char *header="VIXStart";
  143.     char buffer[3];
  144.     int index = 0;
  145.  
  146.     while (true)
  147.     {
  148.  
  149.         int inByte = Serial.read();
  150.         if(inByte==-1)
  151.         {
  152.           continue;
  153.         }
  154.        
  155.         buffer[index] = inByte;
  156.         if(buffer[index]!=header[index])
  157.         {            
  158.             index=-1;                     // not the right sequence restart
  159.         }
  160.        
  161.         buffer[index+1] = 0;              // add null
  162.         index++;
  163.         if(index==8)
  164.         {
  165.           return;
  166.         }
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement