Go Down

Topic: How do I keep all the lights on after a song is played? (Read 136 times) previous topic - next topic

Spankyty

Hi, I have an 8 Channel Vixen 3 light show. When the song is over I do not want it just to be off. I want it to be all on when nothing is playing. I do not want a dark house when my sequence is not playing. Here is the code which works perfect made by Jetty:

Code: [Select]
#define UNO_VIXEN

#ifdef UNO_VIXEN
  #define MAX_CHANNELS 8
  int channels[MAX_CHANNELS] = {5,6,7,8,9,10,11,12};
#endif

int incomingByte[MAX_CHANNELS];

void setup()
{
  int i;
 
  Serial.begin(9600); // set up Serial at 9600 bps

  for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT);
}

void loop()
{
  int i;
 
  if (Serial.available() >= MAX_CHANNELS)
  {
    for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
  }

  for (i = 0; i < MAX_CHANNELS; i ++ )    analogWrite(channels[i], incomingByte[i]);
}


I have an idea of how to do this but I don't know how to code it. It would be greatly appreciated if I got the code to do this:

Create two variables, one to count when a channel is non-zero, and one to set the time to millisec timer. If the count of all channels is zero and stays like that for say a second or two, assume that the sequence has ended and switch all lights ON.

Thanks. :)

patduino

Hi Spankyty,

Try something like this:

Code: [Select]

#define MAX_CHANNELS 8

#define TIMEOUT 5000UL

int channels[MAX_CHANNELS] = {5, 6, 7, 8, 9, 10, 11, 12};

int incomingByte[MAX_CHANNELS];

void setup()
{
  int i;

  Serial.begin(9600); // set up Serial at 9600 bps

  for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT);
}

void loop()
{
  int i;
  static int byteSum = 0;
  static unsigned long lastReadTime = 0;

  if (Serial.available() >= MAX_CHANNELS)
  {
    byteSum = 0;
    for (i = 0; i < MAX_CHANNELS; i ++) {
      incomingByte[i] = Serial.read();
      byteSum += incomingByte[i];
    }
    lastReadTime = millis();
  }

  if ((millis() - lastReadTime >= TIMEOUT) && (byteSum == 0)) {
    for (i = 0; i < MAX_CHANNELS; i ++ ) {
      analogWrite(channels[i], 255);
    }
  }
  else {
    for (i = 0; i < MAX_CHANNELS; i ++ ) {
      analogWrite(channels[i], incomingByte[i]);
    }
  }
}


I think it will do what you want.  The TIMEOUT value is set to 5 seconds, but can be changed to whatever you like

Also - for "code safety" you should get into the habit of always using braces { } in your if and for-loop statements, even if you only have one statement.

Pat.
There are 10 types of people in the world, those who understand binary, and those that don't.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy