

Sent from my iPad using Tapatalk

Sent from my iPad using Tapatalk

Sent from my SM-G920V using Tapatalk

Sent from my SM-G920V using Tapatalk

Sent from my SM-G920V using Tapatalk
Hey everyone,
All good I got everything all hooked up in the nick of time !! lol
just 1 last questions,
I went through a number of older sketches I have collected over the past year.
I have the first sketch up and running my 32 channels and it is successful, I would like to change it a bit if you could help me at the last minute.
The code I am using is written by Victor Perez. Thanks again of the code.
I have another code that I got from somewhere on here late last year. The second code has:
when no read from vixen to have all lights ON and when desired to flip the switch at A0 and A1 for random. My code is little to not I have tried but the compile fails every time. I know i have too many {} or [] that are in the wrong spot.
Could I get a hand cause I like the possibility to leave the system and the lights on constant and the ability to random if I desire.
First code that is current working in my system
[// cHANGED TO CHANNEL 22 - 53 FOR OUTPUT PINS AND ADPTED TO 32 CHANNELS OUT
// This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
// To adapt the code to your case, just change this top section, with the #define lines.
// Vixen needs to be setup to use a header of: ~! there is no footer in this sketch
// -Sets all the channels to off in startup.
// -Wait for up to 2 seconds (can be changed for longer) and if there is no valid input, it goes into random mode, blinking some lights on and off every second.
// -If it detects valid input (with ~! header), it writes to the relays, as long as Vixen is working.
// -If Vixen goes off for more than 2 seconds, back to random mode.
// Includes the watchdog timer library
#include
// This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
#define CHANNEL_COUNT 32
// speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
#define VIXEN_COM_SPEED 57600
// Timeout waiting for serial input before going to random mode (in milliseconds).
#define TIME_OUT 1000
// If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
#define NOT_INVERTED 0
#define INVERTED 1
#define MODE NOT_INVERTED
// which pins control which channels
// You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels.
// DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
#define CH01 22
#define CH02 23
#define CH03 24
#define CH04 25
#define CH05 26
#define CH06 27
#define CH07 28
#define CH08 29
#define CH09 30
#define CH10 31
#define CH11 32
#define CH12 33
#define CH13 34
#define CH14 35
#define CH15 36
#define CH16 37
#define CH17 38
#define CH18 39
// Up to here for Arduino uno.
#define CH19 40
#define CH20 41
#define CH21 42
#define CH22 43
#define CH23 44
#define CH24 45
#define CH25 46
#define CH26 47
#define CH27 48
#define CH28 49
#define CH29 50
#define CH30 51
#define CH31 52
#define CH32 53
// #define CH33 A1
// #define CH34 A2
// #define CH35 A3
// #define CH36 A4
// #define CH37 A5
// #define CH38 A6
// #define CH39 A7
// #define CH40 A8
// #define CH41 A9
// #define CH42 A10
// #define CH43 A11
// #define CH44 A12
// #define CH45 A13
// #define CH46 A14
// #define CH47 A15
// #define CH48 13
int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,CH10,CH11,CH12,CH13,CH14,CH15,CH16,CH17,CH18,CH19,CH20,CH21,CH22,CH23,CH24,CH25,CH26,CH27,CH28,CH29,CH30,CH31,CH32};
//,CH33,CH34,CH35,
// CH36,CH37,CH38,CH39,CH40,CH41,CH42,CH43,CH44,CH45,CH46,CH47,CH48};
int incomingByte[CHANNEL_COUNT];
int i = 0; // Loop counter
volatile unsigned long timer_a = 0; // new line
//setup the pins/ inputs & outputs
void setup(){
// enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
wdt_enable(WDTO_1S);
// specifically for the UNO
// sei();
// initalize PWM Channels / Pins
for (i=0; i < CHANNEL_COUNT; i++){
pinMode(channels, OUTPUT);
}
// set all the realys to off to start with
if (MODE == NOT_INVERTED) {
for (i=0; i < CHANNEL_COUNT; i++){
digitalWrite(channels, LOW);
}
}
else {
for (i=0; i < CHANNEL_COUNT; i++){
digitalWrite(channels, HIGH);
}
}
testSequence();
// set up Serial according to the speed defined above.
Serial.begin(VIXEN_COM_SPEED);
}
void loop()
{
if (Serial.available() >= (CHANNEL_COUNT+2)) {
wdt_reset(); // resets the watchdog
timer_a = millis (); // new line
int uno = Serial.read();
if (uno == 126){
int dos = Serial.read();
if (dos == 33){
for (i=0; i < CHANNEL_COUNT; i++) {
// read each byte
incomingByte = Serial.read();
}
if (MODE == NOT_INVERTED) {
for (i=0; i < CHANNEL_COUNT; i++){
int value = incomingByte;
if (value <= 127) {
digitalWrite(channels, LOW);
}
else {
digitalWrite(channels, HIGH);
}
}
}
else {
for (i=0; i < CHANNEL_COUNT; i++){
int value = incomingByte;
if (value < 127) {
digitalWrite(channels, HIGH);
}
else {
digitalWrite(channels, LOW);
}
}
}
}
}
}
// Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
else {
wdt_reset(); // resets the watchdog
unsigned long diff = millis() - timer_a;
if (diff >= TIME_OUT) {
timer_a = millis ();
int random_a = 0;
for (i=0; i < CHANNEL_COUNT; i++){
random_a = random(0, 2);
if (random_a == 0) {
digitalWrite(channels, LOW);
}
else {
digitalWrite(channels, HIGH);
}
}
}
}
}
void testSequence(){
if (MODE == NOT_INVERTED) {
for (i=0; i < CHANNEL_COUNT; i++){
wdt_reset(); // resets the watchdog
digitalWrite(channels, HIGH);
delay (500);
digitalWrite(channels, LOW);
}
}
else {
for (i=0; i < CHANNEL_COUNT; i++){
wdt_reset(); // resets the watchdog
digitalWrite(channels, LOW);
delay (500);
digitalWrite(channels, HIGH);
}
}
]
now this code that has the switch I found last year
[/*
This sketch allows the Arduino to read 14 bytes of data from Vixen and turn on
its pins accordingly, which for testing purposes are represented by 14 LEDs.
*/
// Define pins on Arduino that will control the LEDs.
#define CHANNEL_01 22
#define CHANNEL_02 23
#define CHANNEL_03 24
#define CHANNEL_04 25
#define CHANNEL_05 26
#define CHANNEL_06 27
#define CHANNEL_07 28
#define CHANNEL_08 29
#define CHANNEL_09 30
#define CHANNEL_10 31
#define CHANNEL_11 32
#define CHANNEL_12 33
#define CHANNEL_13 34
#define CHANNEL_14 35
#define CHANNEL_15 36
#define CHANNEL_16 37
// Define array of channels.
int channels[] =
{
CHANNEL_01, CHANNEL_02, CHANNEL_03, CHANNEL_04, CHANNEL_05, CHANNEL_06, CHANNEL_07, CHANNEL_08,
CHANNEL_09, CHANNEL_10, CHANNEL_11, CHANNEL_12, CHANNEL_13, CHANNEL_14, CHANNEL_15, CHANNEL_16
};
// Define number of channels.
#define CHANNEL_COUNT 16
// Define buffer to store data from Vixen until it gets written to the Arduino.
int incomingByte[16];
// Define the pin that will trigger "random mode".
#define RANDOM_MODE_PIN A0
#define RANDOM_MODE_SPEED 1000
// Define the baud rate for communication with Vixen. This must match that of the Vixen profile!!
#define BAUD_RATE 57600
/*
On first pass through the main loop whilst not in random-mode, the program is forced to turn off
the lights, flush the serial buffer, and then proceed to readFromVixen. Once the program
enters readFromVixen(), the startingVixen variable gets flipped to false, allowing the program to
progress through the 'else' portion of the main loop, which doesn't include flushing the buffer and
turning the lights off; it will only 'readFromVixen()'.
*/
boolean startingVixen = true;
void setup()
{
Serial.begin(BAUD_RATE);
for(int i = 0; i < CHANNEL_COUNT; i++)
{ // Set up each channel as an output.
pinMode(channels, OUTPUT);
}
// Set up the pin for random mode as input.
pinMode(RANDOM_MODE_PIN, INPUT);
turnLightsOff();
powerOnSelfTest();
}
void loop()
{ // If pin is LOW, then turn lights on/off randomly.
if(digitalRead(RANDOM_MODE_PIN) == HIGH)
{
startingVixen = true;
doRandomLights();
}
else
{ // Else, read data from Vixen.
if(startingVixen == true)
{
turnLightsOff();
readFromVixen();
}
}
}
//************** DEFINE FUNCTIONS *********************
// Turn lights off
void turnLightsOff()
{
for(int i = 0; i < CHANNEL_COUNT; i++)
{// Switch from 0 to 255 once I hook up the relays; they're polarity is opposite than LEDs'.
analogWrite(channels, 0);
}
}
// Power on self test.
void powerOnSelfTest()
{
turnLightsOff();
for(int i = 0; i < CHANNEL_COUNT; i++)
{
analogWrite(channels, 255);
delay(500);
analogWrite(channels, 0);
}
turnLightsOff();
}
// Do random light sequence.
void doRandomLights()
{// Read value to pin A1 and generates a random sequence from it.
randomSeed(analogRead(A1));
for(int i = 0; i < CHANNEL_COUNT; i++)
{
int randNumber = random(0, 255);
randNumber = map(randNumber, 0, 255, 255, 0);
if(randNumber <= 127)
{
analogWrite(channels, 255);
}
else
{
analogWrite(channels, 0);
}
}
delay(random(1000, RANDOM_MODE_SPEED));
}
// Read data from Vixen.
void readFromVixen()
{
startingVixen = false;
if (Serial.available() >= CHANNEL_COUNT)
{ // Store incoming bytes to buffer.
for (int i = 0; i < CHANNEL_COUNT; i++)
{
incomingByte = Serial.read();
}
// Write buffer to channels.
for (int i = 0; i < CHANNEL_COUNT; i++)
{
analogWrite(channels, incomingByte);
}
}
}
]
Any help would be great .. I know everyone is trying to get there shows together..
I might be able to help but I'm not clear what your question is.
" My code is little to not I have tried but the compile fails every time. I know i have too many {} or [] that are in the wrong spot."
These quirks are usually caused by people copying and pasting "text code". You should find code that is in code tags to avoid these errors.
I have tried to remove the random timer in the first code and set up the when no communication from vixen to turn all lights on.
And set up the random mode pin input. I seem to miss taking something out or add too much back in
Sent from my iPad using Tapatalk
Could you not just find the original code rather than trying restore what you removed. i.e. Try the experiment again from scratch?
Instead of removing code you could just comment them out with two forward slashes. You can then remove them if you wanted the code back in.
These two I posted are from scratch in touched in the change. I'll try it again when I get back on friday
Sent from my iPad using Tapatalk
I wanna just go outside and scream....these relays are pissing my off
Sent from my SM-G920V using Tapatalk
Your 2nd program compiles for me - if that is what you are looking help for.
I had to remove the 1st [ bracket and the last ] bracket.
Don't why they were put in there, unless the original used code tags and someone cutting&pasting didn't know what they were for.
Always use code tags to post code, else the formatting can get mangled and you end doing a lot of editing.
/*
This sketch allows the Arduino to read 14 bytes of data from Vixen and turn on
its pins accordingly, which for testing purposes are represented by 14 LEDs.
*/
// Define pins on Arduino that will control the LEDs.
#define CHANNEL_01 22
#define CHANNEL_02 23
#define CHANNEL_03 24
#define CHANNEL_04 25
#define CHANNEL_05 26
#define CHANNEL_06 27
#define CHANNEL_07 28
#define CHANNEL_08 29
#define CHANNEL_09 30
#define CHANNEL_10 31
#define CHANNEL_11 32
#define CHANNEL_12 33
#define CHANNEL_13 34
#define CHANNEL_14 35
#define CHANNEL_15 36
#define CHANNEL_16 37
// Define array of channels.
int channels[] =
{
CHANNEL_01, CHANNEL_02, CHANNEL_03, CHANNEL_04, CHANNEL_05, CHANNEL_06, CHANNEL_07, CHANNEL_08,
CHANNEL_09, CHANNEL_10, CHANNEL_11, CHANNEL_12, CHANNEL_13, CHANNEL_14, CHANNEL_15, CHANNEL_16
};
// Define number of channels.
#define CHANNEL_COUNT 16
// Define buffer to store data from Vixen until it gets written to the Arduino.
int incomingByte[16];
// Define the pin that will trigger "random mode".
#define RANDOM_MODE_PIN A0
#define RANDOM_MODE_SPEED 1000
// Define the baud rate for communication with Vixen. This must match that of the Vixen profile!!
#define BAUD_RATE 57600
/*
On first pass through the main loop whilst not in random-mode, the program is forced to turn off
the lights, flush the serial buffer, and then proceed to readFromVixen. Once the program
enters readFromVixen(), the startingVixen variable gets flipped to false, allowing the program to
progress through the 'else' portion of the main loop, which doesn't include flushing the buffer and
turning the lights off; it will only 'readFromVixen()'.
*/
boolean startingVixen = true;
void setup()
{
Serial.begin(BAUD_RATE);
for(int i = 0; i < CHANNEL_COUNT; i++)
{ // Set up each channel as an output.
pinMode(channels[i], OUTPUT);
}
// Set up the pin for random mode as input.
pinMode(RANDOM_MODE_PIN, INPUT);
turnLightsOff();
powerOnSelfTest();
}
void loop()
{ // If pin is LOW, then turn lights on/off randomly.
if(digitalRead(RANDOM_MODE_PIN) == HIGH)
{
startingVixen = true;
doRandomLights();
}
else
{ // Else, read data from Vixen.
if(startingVixen == true)
{
turnLightsOff();
readFromVixen();
}
}
}
//************** DEFINE FUNCTIONS *********************
// Turn lights off
void turnLightsOff()
{
for(int i = 0; i < CHANNEL_COUNT; i++)
{// Switch from 0 to 255 once I hook up the relays; they're polarity is opposite than LEDs'.
analogWrite(channels[i], 0);
}
}
// Power on self test.
void powerOnSelfTest()
{
turnLightsOff();
for(int i = 0; i < CHANNEL_COUNT; i++)
{
analogWrite(channels[i], 255);
delay(500);
analogWrite(channels[i], 0);
}
turnLightsOff();
}
// Do random light sequence.
void doRandomLights()
{// Read value to pin A1 and generates a random sequence from it.
randomSeed(analogRead(A1));
for(int i = 0; i < CHANNEL_COUNT; i++)
{
int randNumber = random(0, 255);
randNumber = map(randNumber, 0, 255, 255, 0);
if(randNumber <= 127)
{
analogWrite(channels[i], 255);
}
else
{
analogWrite(channels[i], 0);
}
}
delay(random(1000, RANDOM_MODE_SPEED));
}
// Read data from Vixen.
void readFromVixen()
{
startingVixen = false;
if (Serial.available() >= CHANNEL_COUNT)
{ // Store incoming bytes to buffer.
for (int i = 0; i < CHANNEL_COUNT; i++)
{
incomingByte[i] = Serial.read();
}
// Write buffer to channels.
for (int i = 0; i < CHANNEL_COUNT; i++)
{
analogWrite(channels[i], incomingByte[i]);
}
}
}
I have both codes working, I want to combine the two to remove the random timer and make them go constant.
I wnat this part of the second code
// Do random light sequence.
void doRandomLights()
{// Read value to pin A1 and generates a random sequence from it.
randomSeed(analogRead(A1));
for(int i = 0; i < CHANNEL_COUNT; i++)
{
int randNumber = random(0, 255);
randNumber = map(randNumber, 0, 255, 255, 0);
if(randNumber <= 127)
{
analogWrite(channels[i], 255);
}
else
{
analogWrite(channels[i], 0);
}
}
delay(random(1000, RANDOM_MODE_SPEED));
}
in the first one in place of this part of the code
// Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
else {
wdt_reset(); // resets the watchdog
unsigned long diff = millis() - timer_a;
if (diff >= TIME_OUT) {
timer_a = millis ();
int random_a = 0;
for (i=0; i < CHANNEL_COUNT; i++){
random_a = random(0, 2);
if (random_a == 0) {
digitalWrite(channels[i], LOW);
I seem to mess it up when removing the random watchdog and trying to get the switch and static lights on
sorry man!
i have it almost together should have the boxes in place on Wednesday for the first show.
good luck getting it together

