#define NCH 8 // ALTER THIS: the sum of pwm and digital pins (number of channels from vixen)
#define NPWM 6 // ALTER THIS: the number of PWM pins you use
#define NDIG 2 // ALTER THIS: the number of DIGITAL pins you use...make sure NPWM+NDIG=NCH
int pins[NCH]={ 3,5,6,9,10,11, 7,8 }; //ALTER THIS FOR YOUR PHYSICAL PINS...pwm first then normal digital pins (set for UNO currently)
int data[NCH]; // to buffer incoming data
void setup()
{
Serial.begin(9600); // ALTER THIS: for various serial speeds on Vixen
for (int i=0; i<NCH; i++) pinMode ( pins[i], OUTPUT );
}
void readSerialBuffer() { for (int i=0; i<NCH; i++) data[i] = Serial.read(); }
void outputToPins() {
for (int i=0; i<NPWM; i++) analogWrite(pins[i], data[i]); // first pwm
for (int i=NPWM; i<NCH; i++) // now digital outputs
if (data[i]<127) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH);
}
void loop()
{
if (Serial.available() >= NCH) {
readSerialBuffer();
outputToPins();
}
}
Auld,
Thanks for the code. It works great! We should have an awesome show for halloween now.
It works! Thanks so much! Now my Halloween/Christmas display is one step closer!
Hey that's great, glad to help.
Another noob here, thanks for your code. I was banging my head against the wall trying to get it to work until finally I realized I had the wrong baud rate set in Vixen. Works perfectly!
Vixen Lights is awesome and I wanted to have it control my new little Arduino Duemilanove. I decided to use the generic serial output already in vixen lights as my plugin. I’m using 5 channels on my Arduino (5,6,9,10 & 11) that have PWM so I can fade the LEDs. The generic serial output appears to simply output one byte at a time like so: 06 00 00 00 00 00 0d. I setup my vixen lights sequence to use 7 channels. The first 5 would be for my LEDs, channel 6 is the beat track and channel 7 was a spare. I used a baud rate of 9600. The code simply takes the 7 bytes, stuffs them into an array and then sends them to the hungry LEDs. Check out the code:
Code:/* The purpose of this code is to allow the Arduino to use the generic serial output of vixen lights to control 5 channels of LEDs. Author: Matthew Strange Created: 14 October 2010 */ // Output int Chan1 = 5; // red LED, connected to digital pin 5 int Chan2 = 6; // green LED, connected to digital pin 6 int Chan3 = 9; // red LED, connected to digital pin 9 int Chan4 = 10; // green LED, connected to digital pin 10 int Chan5 = 11; // red LED, connected to digital pin 11 int i = 0; // Loop counter int incomingByte[7]; // array to store the 7 values from the serial port //setup the pins/ inputs & outputs void setup() { Serial.begin(9600); // set up Serial at 9600 bps pinMode(Chan1, OUTPUT); // sets the pins as output pinMode(Chan2, OUTPUT); pinMode(Chan3, OUTPUT); pinMode(Chan4, OUTPUT); pinMode(Chan5, OUTPUT); } void loop() { // 7 channels are coming in to the Arduino if (Serial.available() >= 7) { // read the oldest byte in the serial buffer: for (int i=0; i<8; i++) { // read each byte incomingByte[i] = Serial.read(); } analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins } }
Simple and easy. This will only work with a 7 channel output. I can see complications if you wanted to grow this more. Which I do! Next steps will be to daisy chain some Arduinos, and add some SSRs. I’m completely new so I hope this helps another noobie. Any comments or suggestions are appreciated.