123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
/*
Beambox - The Tower that Glows to Your Commands
http://www.instructables.com/id/BeamBox-A-tower-that-glows-to-your-commands/
By PerfectPixel 2016
Code by JDC928 (source here: http://doityourselfchristmas.com/forums/showthread.php?31079-Arduino-code-for-driving-RGB-Addressable-pixels-from-Vixen )
Edited by PerfectPixel
Requires Adafruits NEOPIXEL library instead of the FastLED library
Neopixel Library Available Here:
https://github.com/adafruit/Adafruit_NeoPixel
To Get Started Download Vixen ( http://www.vixenlights.com/ )
and follow the instructions below
*/
/* VIXEN Setup:
* In Vixen display setup...
* - Add an element group containing one element for each pixel attached to arduino
* - Configure the 'Color Handling' as "They can be any color: Full RGB"
* - Add a "Generic Serial Controller"
* - Name it what you want (Although... Jdc928IsAwesome is great controller name)
* - Set the channel count to 3x the number of Pixels you have
* - Save, then configure these options
* - Com Port: choose the correct port for your arduino's serial
* - Baud Rate: 115200 (or whatever you changed it to below)
* - Click OK
* - Check the box "Send a text header"
* - Type "VIXStart" in the header text box
* - Click "OK"
*
* - Click and highlight the newly added Element in the elements list
* - Click and highlight the newly created controller
* - Your "Total Patch Points" and "Output" counts should match
* - Click "Patch Elements to Controllers"
* - Click OK and you should be ready to go
*
*
* You should now be able open a Sequence
add some effects to the new channels
and see the strips responding accordingly
*/
/**
* Pixel Strip Setup
* Strips setups vary but generally as follows
* - If your using a large number of strips you will
* probably want to power them externally.
*
* - Connect external V+ to strip Vin
* - Connect external Gnd to strip Gnd
* - Connect external Gnd to Arduino Gnd
* - Connect Strip Data to proper pin on Arduino
* - Connect Strip DataClock to proper pin on Arduino if not using ws2812
*/
#include <Adafruit_NeoPixel.h> // This is the Neo-Pixel library (ws2812)
// Change to the library for your pixel types
// Suggest using a library created by Adafruit
// so the function names will be the same
#define DPIN 9 // Change this to the pin# connected to your pixels DataIn
// Will probably need to define a ClockPin for other pixel
int PixelCount = 18; // Set this to the number of Pixels connected
int bugLevel = 0; // This is just a way I manage turning debugging over serial on/off
/* Sets up the NeoPixel Strip object
Replace with proper Object initiation for your pixel types */
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PixelCount, DPIN, NEO_GRB + NEO_KHZ800);
void setup()
{
delay(100); // A delay for a reason I can't remember. I can live with one in the setup.
strip.begin(); // Get strip started
strip.show(); // Initialize all pixels to 'off'
Serial.begin(115200); // Start the Serial communication
}
void loop()
{ // START LOOP
if (Serial.available()>2) // Wait for a few bytes to be recieved
{
waitForVixenHeader(); // Header check function
for (int pixCount=0; pixCount<PixelCount;pixCount++) // Do this for as many Pixels defined in PixelCount
{
int RGB[3]; // Create array to hold this pixels RGB value
for (int color = 0;color<3;color++) // For the next 3 incoming bytes
{
while (Serial.available() < 1) // Wait for bytes to be received
{
delay(10);
}
RGB[color] = Serial.read(); // Save this byte to the correct RGB value
} // Repeat until bytes for this pixels RGB value have been recieved
strip.setPixelColor(pixCount,RGB[0],RGB[1],RGB[2]); //Set this pixels new color
} // Repeat untill all pixels have had new RGB value set
strip.show(); // Update the strip and show with new color
} // YAY! DO IT AGAIN!
} // END OF LOOP
/**
* FUNC bugit [manages printing of debugging based on debugging level]
* @param String bugstr [string to be be printed]
* @param int blevel [the level at which this debugging should be ignored]
*
*/
/**
* I 'borrowed' snippets of this waitForVixenHeader() function from some code I found online
* Can't find the originator now but thank you. It works well.
*
*/
void waitForVixenHeader()
{
char *header="VIXStart";
char buffer[3];
int index = 0;
while (true)
{
int inByte = Serial.read();
if(inByte==-1)
{
continue;
}
buffer[index] = inByte;
if(buffer[index]!=header[index])
{
index=-1; // not the right sequence restart
}
buffer[index+1] = 0; // add null
index++;
if(index==8)
{
return;
}
}
}