How do I keep all the lights on after a song is played?

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:

#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. :slight_smile:

Hi Spankyty,

Try something like this:

#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.