Fading LEDs on and off to a brightness specified via Serial

Hello! I am working on creating a display that fades some lights on and off in time with an audio program. I have 4 lights- one is always on, two should fade on for a bit and then fade off while the fourth fades on, after the fourth is on for a bit it fades back off while the two fade on again, and then the two fade back off. I also want the option to adjust the first light's brightness.

I'm using a BrightSign (HD224 Standard I/O Player :: BrightSign) to control the audio and to send brightness values to my Arduino Uno. With the BrightSign, I can adjust the brightness values when the display is set up. For now, my issue is with coding the Uno.

After a lot of searching, I found this library (GitHub - bhagman/SoftPWM: A Wiring (and Arduino) Library to produce PWM signals on arbitrary pins.) that got me to something that sort of does what I need. My code will fade a light on and off to a brightness specified via serial command, but only after it turns on abruptly and fades off once. When it's running, I want it to always fade on and fade off. Here's that code:

#include "SoftPWM.h"

void setup() {
  // Initialize
  SoftPWMBegin();

  int light = 6;
  pinMode(light, OUTPUT);

  // Create and set pin 6 to 0 (off)
  SoftPWMSet(light, 0);

  // Set fade time for pin 6 to 1000 ms fade-up time, and 1000 ms fade-down time
  SoftPWMSetFadeTime(light, 1000, 1000);
  Serial.begin(9600);
}

void loop() {
  int light = 6;
  int brightness = Serial.parseInt();
  while (Serial.available() > 0) {

    // first time the light turns on, it blinks on and fades off
    SoftPWMSet(light, 0);
    delay(1000);
    SoftPWMSet(light, 255);
    delay(1000);

    // this time, it will fade on and off as intended
    SoftPWMSet(light, 0);
    delay(1000);
    SoftPWMSet(light, brightness);
    delay(1000);
    SoftPWMSet(light, 0);

    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {
      Serial.print(brightness);
      Serial.print(",");
    }
  }
}

Eventually, I also need this to happen with my four lights- I have not yet tried to control multiple lights at once with this code. I found an example (https://docs.arduino.cc/built-in-examples/communication/ReadASCIIString) on how to do something similar but with an RGB LED, but I'm planning to wire it so that the different colors are actually entirely different lights. Once I get the fading code working, I'll combine it with this code so I can control my 4 LEDs. Here's the example code:

/*

  Reading a serial ASCII-encoded string.

  This sketch demonstrates the Serial parseInt() function.

  It looks for an ASCII string of comma-separated values.

  It parses them into ints, and uses those to fade an RGB LED.

  Circuit: Common-Cathode RGB LED wired like so:

  - red anode: digital pin 3

  - green anode: digital pin 5

  - blue anode: digital pin 6

  - cathode: GND

  created 13 Apr 2012

  by Tom Igoe

  modified 14 Mar 2016

  by Arturo Guadalupi

  This example code is in the public domain.

*/

// pins for the LEDs:

const int redPin = 3;

const int greenPin = 5;

const int bluePin = 6;

void setup() {

  // initialize serial:

  Serial.begin(9600);

  // make the pins outputs:

  pinMode(redPin, OUTPUT);

  pinMode(greenPin, OUTPUT);

  pinMode(bluePin, OUTPUT);

}

void loop() {

  // if there's any serial available, read it:

  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:

    int red = Serial.parseInt();

    // do it again:

    int green = Serial.parseInt();

    // do it again:

    int blue = Serial.parseInt();

    // look for the newline. That's the end of your sentence:

    if (Serial.read() == '\n') {

      // constrain the values to 0 - 255 and invert

      // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"

      red = 255 - constrain(red, 0, 255);

      green = 255 - constrain(green, 0, 255);

      blue = 255 - constrain(blue, 0, 255);

      // fade the red, green, and blue legs of the LED:

      analogWrite(redPin, red);

      analogWrite(greenPin, green);

      analogWrite(bluePin, blue);

      // print the three numbers in one string as hexadecimal:

      Serial.print(red, HEX);

      Serial.print(green, HEX);

      Serial.println(blue, HEX);

    }

  }
}

It seems like I'm really close to getting it to work- is there something off about the code I'm using, or am I going about it all wrong to begin with?

Thanks!

The basic error you and Tom are making is:-

And then you are going on to read three bytes from the serial port, when all you know for sure is that you have at least 1 to read.

How are you inputting the serial data? Because if it is from a keyboard attached to the serial monitor then you are receiving three bytes when you type "158", not a value of 158.

Look at Serial Input Basics - updated

Why declare int light in setup and in loop? Why not?

#define light 6

The value of brightness is changed BEFORE you control that there are bytes in the serial buffer.

void loop() {
  int brightness;
  while (Serial.available() > 0) {
   brightness = Serial.parseInt();
    // first time the light turns on, it blinks on and fades off
    SoftPWMSet(light, 0);
    delay(1000);
    SoftPWMSet(light, 255);
    delay(1000);

    // this time, it will fade on and off as intended
    SoftPWMSet(light, 0);
    delay(1000);
    SoftPWMSet(light, brightness);
    delay(1000);
    SoftPWMSet(light, 0);

    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {
      Serial.print(brightness);
      Serial.print(",");
    }
  }
}

You can declare int brightness as global variabele. In loop he have a live in that scope.

Thank you! I've made those changes now and eliminated superfluous code, which makes the whole thing look a bit neater and more efficient. Unfortunately, I'm still having the problem where the light won't fade on at first. Do you have any more ideas for me to try? Thanks again

What do you mean?

    // first time the light turns on, it blinks on and fades off
    SoftPWMSet(light, 0);
    delay(1000);
    SoftPWMSet(light, 255);
    delay(1000);

Must this be happen once before the first character is send to the Serial input?

Then this code must in the setup section.

This description is confusing and lets things unspecified
does "

mean going from light switched totally off to light has a bit brightness let's say 10% of maximum-brightness or does it mean fading in for a bit of time ?

or both very slowly fading it but only for short so that at the end of fading in only 10% brightness is reached?

what does it mean

light 4 has faded in until maximum brightness, then stays on for a bit of time at maximum brightness then fades out again??

Your description is like asking Amazon Alexa

"Alexa make me happy"
What does that mean? please specify
turning on what kind of music? to what level?
ordering a meal? which one? from what service?
switching on TV? which live-channel? playing which film?

Draw a timing chart that shows all four lights and how these lights emiting light at which brightness-level over time

best regards Stefan

I've had to change strategies because once I got the SoftPWM code to do what I wanted, it would cause a slight flicker in my lights while dimming on and off. I decided to adapt the Fade example code instead, which works very well with my computer.

The problem now is that I'm connecting the Arduino to a BrightSign, which will control the lights in time with an audio, but they don't seem to be communicating as I intended. At 250, 16000, and 42000 milliseconds, the BrightSign sends a Serial String to the Arduino. For example, at 250ms it sends "11111111,00000000,11111111,01100100" (255,0,255,100 in binary- BrightSign doesn't have an option to send decimal strings, so far as I've found). This combination does exactly what I expect when connected to my Mac, but when it's connected to the BrightSign the lights will flash fully on abruptly and then fade fully off repeatedly over the course of about 2 seconds (this cycles indefinitely until power is cut).

I'm not sure if I need to adjust my code to listen to the BrightSign differently, or if I need to adjust the BrightSign program itself. With my previous code (the SoftPWM), the BrightSign would turn the lights on and off at the appropriate times. Any suggestions would be greatly appreciated.

Here is the code I'm working with (the adapted Fade example):

#define a 3  // This is the LED strip at the front of the display. It stays on after the program runs.
#define b 5  // This is the light for the archaeological dig model.
#define x 6  // This is the LED strip at the front of the display that turns on and off during the program to illuminate the exterior of the house.
#define y 9  // This is for the lights inside the house, barrel, and moon.
// the following are the starting brightness values for each pin
int abright = 255;  // a starts at 255 because this channel should come on full when the system powers up
int bbright = 0;
int xbright = 0;
int ybright = 0;
const int fadeAmount = 5;  // how many points to fade the lights by
const int time = 30;       // how many milliseconds to delay (controls the rate of the fade)

void setup() {
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(x, OUTPUT);
  pinMode(y, OUTPUT);
  Serial.begin(9600);
  analogWrite(a, abright);
  analogWrite(b, bbright);
  analogWrite(x, xbright);
  analogWrite(y, ybright);  // Set a to turn on fully when power turns on, all other lights remain off.
}

void loop() {
  int a1;
  int b1;
  int x1;
  int y1;
  // These establish the light levels. The lights will turn on to any value 0-255 as determined by the serial input below.

  while (Serial.available() > 0) {
    a1 = Serial.parseInt();
    b1 = Serial.parseInt();
    x1 = Serial.parseInt();
    y1 = Serial.parseInt();

    while (abright != a1) {
      analogWrite(a, abright);
      analogWrite(b, bbright);
      analogWrite(x, xbright);
      analogWrite(y, ybright);
      // defines brightnesses
      if (abright > a1) {
        abright = abright - fadeAmount;
      } else {
        if (abright < a1) {
          abright = abright + fadeAmount;
        } else {
          abright = abright;
        }
      }
      if (bbright > b1) {
        bbright = bbright - fadeAmount;
      } else {
        if (bbright < b1) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
      }
      if (xbright > x1) {
        xbright = xbright - fadeAmount;
      } else {
        if (xbright < x1) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
      }
      if (ybright > y1) {
        ybright = ybright - fadeAmount;
      } else {
        if (ybright < y1) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
      }
      // wait to see the dimming effect- time is a const int established on line 11
      delay(time);
      // serial print the target values and the changing brightnesses to more easily track the progress
      Serial.print(a1);
      Serial.print(",");
      Serial.print(abright);
      Serial.print(",");
      Serial.print(b1);
      Serial.print(",");
      Serial.print(bbright);
      Serial.print(",");
      Serial.print(x1);
      Serial.print(",");
      Serial.print(xbright);
      Serial.print(",");
      Serial.print(y1);
      Serial.print(",");
      Serial.print(ybright);
      Serial.println();
      // ensures a turns off fully if it's supposed to
      if (a1 <= 0) {
        analogWrite(a, 0);
      }
    }
    while (bbright != b1) {
      analogWrite(a, abright);
      analogWrite(b, bbright);
      analogWrite(x, xbright);
      analogWrite(y, ybright);
      // defines brightnesses
      if (abright > a1) {
        abright = abright - fadeAmount;
      } else {
        if (abright < a1) {
          abright = abright + fadeAmount;
        } else {
          abright = abright;
        }
      }
      if (bbright > b1) {
        bbright = bbright - fadeAmount;
      } else {
        if (bbright < b1) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
      }
      if (xbright > x1) {
        xbright = xbright - fadeAmount;
      } else {
        if (xbright < x1) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
      }
      if (ybright > y1) {
        ybright = ybright - fadeAmount;
      } else {
        if (ybright < y1) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
      }
      // wait to see the dimming effect- time is a const int established on line 11
      delay(time);
      // serial print the target values and the changing brightnesses to more easily track the progress
      Serial.print(a1);
      Serial.print(",");
      Serial.print(abright);
      Serial.print(",");
      Serial.print(b1);
      Serial.print(",");
      Serial.print(bbright);
      Serial.print(",");
      Serial.print(x1);
      Serial.print(",");
      Serial.print(xbright);
      Serial.print(",");
      Serial.print(y1);
      Serial.print(",");
      Serial.print(ybright);
      Serial.println();
      // ensures b turns off fully if it's supposed to
      if (b1 <= 0) {
        analogWrite(b, 0);
      }
    }
    while (xbright != x1) {
      analogWrite(a, abright);
      analogWrite(b, bbright);
      analogWrite(x, xbright);
      analogWrite(y, ybright);
      // defines brightnesses
      if (abright > a1) {
        abright = abright - fadeAmount;
      } else {
        if (abright < a1) {
          abright = abright + fadeAmount;
        } else {
          abright = abright;
        }
      }
      if (bbright > b1) {
        bbright = bbright - fadeAmount;
      } else {
        if (bbright < b1) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
      }
      if (xbright > x1) {
        xbright = xbright - fadeAmount;
      } else {
        if (xbright < x1) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
      }
      if (ybright > y1) {
        ybright = ybright - fadeAmount;
      } else {
        if (ybright < y1) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
      }
      // wait to see the dimming effect- time is a const int established on line 11
      delay(time);
      // serial print the target values and the changing brightnesses to more easily track the progress
      Serial.print(a1);
      Serial.print(",");
      Serial.print(abright);
      Serial.print(",");
      Serial.print(b1);
      Serial.print(",");
      Serial.print(bbright);
      Serial.print(",");
      Serial.print(x1);
      Serial.print(",");
      Serial.print(xbright);
      Serial.print(",");
      Serial.print(y1);
      Serial.print(",");
      Serial.print(ybright);
      Serial.println();
      // ensures x turns off fully if it's supposed to
      if (x1 <= 0) {
        analogWrite(x, 0);
      }
    }
    while (ybright != y1) {
      analogWrite(a, abright);
      analogWrite(b, bbright);
      analogWrite(x, xbright);
      analogWrite(y, ybright);
      // defines brightnesses
      if (abright > a1) {
        abright = abright - fadeAmount;
      } else {
        if (abright < a1) {
          abright = abright + fadeAmount;
        } else {
          abright = abright;
        }
      }
      if (bbright > b1) {
        bbright = bbright - fadeAmount;
      } else {
        if (bbright < b1) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
      }
      if (xbright > x1) {
        xbright = xbright - fadeAmount;
      } else {
        if (xbright < x1) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
      }
      if (ybright > y1) {
        ybright = ybright - fadeAmount;
      } else {
        if (ybright < y1) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
      }
      // wait to see the dimming effect- time is a const int established on line 11
      delay(time);
      // serial print the target values and the changing brightnesses to more easily track the progress
      Serial.print(a1);
      Serial.print(",");
      Serial.print(abright);
      Serial.print(",");
      Serial.print(b1);
      Serial.print(",");
      Serial.print(bbright);
      Serial.print(",");
      Serial.print(x1);
      Serial.print(",");
      Serial.print(xbright);
      Serial.print(",");
      Serial.print(y1);
      Serial.print(",");
      Serial.print(ybright);
      Serial.println();
      // ensures y turns off fully if it's supposed to
      if (y1 <= 0) {
        analogWrite(y, 0);
      }
    }
    // ensures each light has turned off fully if it's supposed to, just in case the above code misses it
    if (a1 <= 0) {
      analogWrite(a, 0);
    }
    if (b1 <= 0) {
      analogWrite(b, 0);
    }
    if (x1 <= 0) {
      analogWrite(x, 0);
    }
    if (y1 <= 0) {
      analogWrite(y, 0);
    }
  }
}

Here is the previous code (SoftPWM):

#include "SoftPWM.h"  // This is the code from a library that allowed us to dim the lights.

#define general 3  // This is the LED strip at the front of the display. It stays on after the program runs.
#define dig 5      // This is the light for the archaeological dig model.
#define house 6    // This is the LED strip at the front of the display that turns on and off during the program to illuminate the exterior of the house.
#define inside 9   // This is for the lights inside the house, barrel, and moon.

void setup() {
  // Initialize.
  SoftPWMBegin();

  pinMode(general, OUTPUT);
  pinMode(dig, OUTPUT);
  pinMode(house, OUTPUT);
  pinMode(inside, OUTPUT);


  // Create and set pins to 0 (off).
  SoftPWMSet(general, 0);
  SoftPWMSet(dig, 0);
  SoftPWMSet(house, 0);
  SoftPWMSet(inside, 0);

  // Set fade time for pins to 4000 ms fade-up time, and 4000 ms fade-down time.
  SoftPWMSetFadeTime(general, 4000, 4000);
  SoftPWMSetFadeTime(dig, 4000, 4000);
  SoftPWMSetFadeTime(house, 4000, 4000);
  SoftPWMSetFadeTime(inside, 4000, 4000);

  Serial.begin(9600);
  SoftPWMSet(general, 255);
  SoftPWMSet(dig, 0);
  SoftPWMSet(house, 0);
  SoftPWMSet(inside, 0);  // Set general to turn on fully when power turns on, all other lights remain off.
}

void loop() {

  int general1;
  int dig1;
  int house1;
  int inside1;
  // These establish the light levels. The lights will turn on to any value 0-255 as determined by the serial input below.
  while (Serial.available() > 0) {
    general1 = Serial.parseInt();
    dig1 = Serial.parseInt();
    house1 = Serial.parseInt();
    inside1 = Serial.parseInt();

    SoftPWMSet(general, general1);
    SoftPWMSet(dig, dig1);
    SoftPWMSet(house, house1);
    SoftPWMSet(inside, inside1);
    // When you input a string of four numbers through a serial command, the Arduino reads them in the above order and will set the corresponding light to the entered value, fading on/off according to the set Fade Time.

    // This is not necessary for the code to function, but it did make the set-up process easier.
    Serial.print(general1);
    Serial.print(",");
    Serial.print(dig1);
    Serial.print(",");
    Serial.print(house1);
    Serial.print(",");
    Serial.print(inside1);
    Serial.print(",");

    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {  //this is necessary for the brightsign, otherwise all the lights will turn themselves off after a few seconds (in the middle of the program as well as at the end).
    }
  }
}

And here are my settings for the BrightSign:
First, this is under Presentation Settings>>Interactive>>Connectors>>Serial:
image

Using an Audio Time Code Event, I've established these commands (which I also described above):
image

As a general advice:

If you use a new component start with a working example.
Then do small modifications toward the final code.

If you don't have a working example start very very basic and work up from there.

You haven't yet understood that you can only expect help if you provide sufficient information
In this case the sufficient information is a link to the datasheet and the usermanual of your bright-sign.

Do you really expect the user here to dig the internet for this datasheet and usermanual???

Thanks for the quick response, Stefan. As I said in my last reply, I've gotten the new component to work with my previous code (the SoftPWM one)- to get there, I started small and worked up to that point, then did the same as I switched to my new code. Thank you for the reminder, though.

Here is the datasheet and the usermanual, as requested. BrightAuthor is the software for programming the BrightSigns and individual BrightSigns do not have their own manuals. I have attempted this program with both an HD1024 and an XT1144, both to the same result as I described above.

what is the

???

which exact post # -number is

???

what is a "HD1024" / what is a "XT1144"? ?? ???

what is the coupling element between the arduino and this "other thing"????

tips how to improve your posting style

Hi again Stefan. It seems we're having a miscommunication, as I'm not leaving out information.

I took your statement here as "If you use a new piece of technology with your code, start with a working example", as I said:

and the BrightSign is the piece of technology I have now introduced into my project (I had not gotten to this phase when I originally posted my first question on Nov 4). If you were actually referring to a new segment of code, that is not applicable: I wrote entirely new code.

Here, I am referring to

By "previous", I mean "the code I posted the original question about" as well as "the code I tried initially for this project". That code worked with my BrightSign, but it wasn't a clean fade on or off, as I explained here:

The code I am currently working on is my adapted version of the Fade example (I've included this link to the example page on the Arduino site just in case). My version is controlled via serial and applies to 4 channels of LEDs. This adapted version is in my first reply of the day, but for convenience I'll quote it here:

These are the names of the BrightSign models I've used for this project. XT1144 is the one I currently have easiest access to, so I included the datasheet for that one in my previous reply, if you click on the link here:

You'll see the "XT1144" name in the middle of the first page of that PDF.

My Arduino Uno is connected to the BrightSign XT1144 from the Uno's USB-B cable to the XT1144's USB-A port. The XT1144 sends the Serial data to the Uno.

It seems like you are unfamiliar with BrightSigns, so if you are unable to help I understand and thank you for your time so far. Please let me know if you have more questions, and apologies for the miscommunication.

This is the most important part to know.
There is a device the XT1144 that is sending serial data to the Arduino-Uno.

To analyse what your XT1144 is exactly sending a small testcode on the arduino Uno can be used.
This testcode is simply echoing each character that is received from the XT1144.

The datasheet of the XT1144 talks about high performance video rendering.
Does this mean the XT1144 is a special kind of windows-computer?

Are you running the Ardunio-IDE on the XT1144 computer?

If the XT1144 can not run the arduino-IDE an additional USB-to-TTL-converter would be very useful. This additional USB-to-TTL-converter would then be connected to the Arduino-IDE-PC to
receive and print the characters echoed by the arduino-Uno.

best regards Stefan

I've gotten a solution! Originally, the goal was to have the BrightSign determine the brightness levels of the lights as well as the timing of the changes. Using an LCD, I realized the BrightSign wasn't sending what I expected it to send, so I decided to pivot. Rather than have the BrightSign set the brightness levels, I changed my code again so the Arduino sets the levels when the BrightSign would tell it to. Now, it works great! I've reached out to the support staff at BrightSign to try to determine what I'm missing that's preventing me from what I'd originally tried to do, so I'll update here again if I ever figure it out. In the meantime, here's the code that works, including all 4 channels and all 4 timestamps:

const int a = 3;  // This is the LED strip at the front of the display. It stays on after the program runs.
const int b = 5;  // This is the light for the archaeological dig model.
const int x = 6;  // This is the LED strip at the front of the display that turns on and off during the program to illuminate the exterior of the house.
const int y = 9;  // This is for the lights inside the house, barrel, and moon.

// the following are the starting brightness values for each pin
int abright = 255;  // a starts at 255 because this channel should come on full when the system powers up
int bbright = 0;
int xbright = 0;
int ybright = 0;

const int fadeAmount = 5;  // how many points to fade the lights by
const int time = 30;       // how many milliseconds to delay (controls the rate of the fade)

// the following integers are the desired brightness levels of each light at each timestamp and at the end of the program. if the levels need to be adjusted, this is the only spot you need to update the numbers
const int a1 = 255;
const int x1 = 255;
const int y1 = 175;  // this set is for timestamp 1; there is no "b1" because b will never need to change at the first timestamp

const int a2 = 255;
const int b2 = 150;
const int x2 = 0;
const int y2 = 0;  // this set is for timestamp 2

const int a3 = 255;
const int b3 = 0;
const int x3 = 255;
const int y3 = 175;  // this set is for timestamp 3

const int aend = 255;
const int xend = 0;
const int yend = 0;  // this set is for the end of the media; there is no "bend" because b will never need to change at the end of the media

void setup() {
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(x, OUTPUT);
  pinMode(y, OUTPUT);

  Serial.begin(9600);
  analogWrite(a, abright);
  analogWrite(b, bbright);
  analogWrite(x, xbright);
  analogWrite(y, ybright);  // Set lights to what they should be when power turns on
}


void loop() {
  const int stamp1 = 1;
  const int stamp2 = 2;
  const int stamp3 = 3;
  const int end = 4;
  // the "stamp" integers represent different timestamps in the audio; "end" is for "media end". the brightsign sends serial strings through an "audio time code" event and a "media end" event
  int bs;  // this is the serial string the brightsign sends

  while (Serial.available() > 0) {
    bs = Serial.parseInt();

    if (bs == stamp1) {        // if the brightsign sends stamp1 (which is "1", see line 42), the following code happens- this should happen at the first timestamp marked in the audio on the brightsign
      while (abright != a1) {  // when the brightness of a is not equal to a1 (the brightness goal set in line 19), the following code loops until a has reached the brightness goal
        analogWrite(a, abright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);  // set each light to the appropriate brightness. since "b" does not change from the setup during this timestamp, it has been excluded
        // defines brightnesses
        if (abright < a1) {  //if a is still less than the brightness goal, it will increase by the fadeAmount until it reaches the goal. if a is already at the goal, the light will not change at all
          abright = abright + fadeAmount;
        } else {
          if (abright == a1) {
            abright = abright;
          }
        }
        if (xbright < x1) {  //if x is still less than the brightness goal, it will increase by the fadeAmount until it reaches the goal. if x is already at the goal, the light will not change at all
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y1) {  //if y is still less than the brightness goal, it will increase by the fadeAmount until it reaches the goal. if y is already at the goal, the light will not change at all
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures a turns off fully if it's supposed to
        if (a1 <= 0) {
          analogWrite(a, 0);
        }
      }
      while (xbright != x1) {  // when the brightness of x is not equal to x1 (the brightness goal set in line 19), the following code loops until x has reached the brightness goal. this is the same code as lines 57 through 81, but applied to light x- this is in case a reaches its goal before x can do the same. this code repeats for each light in every timestamp, but with minor adjustments that will be noted at that point
        analogWrite(a, abright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright < a1) {
          abright = abright + fadeAmount;
        } else {
          if (abright == a1) {
            abright = abright;
          }
        }
        if (xbright < x1) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y1) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures x turns off fully if it's supposed to
        if (x1 <= 0) {
          analogWrite(x, 0);
        }
      }
      while (ybright != y1) {
        analogWrite(a, abright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright < a1) {
          abright = abright + fadeAmount;
        } else {
          if (abright == a1) {
            abright = abright;
          }
        }
        if (xbright < x1) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y1) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures y turns off fully if it's supposed to
        if (y1 <= 0) {
          analogWrite(y, 0);
        }
      }
      // ensures each light turns off fully if it's supposed to, just in case the above code misses it
      if (a1 <= 0) {
        analogWrite(a, 0);
      }
      if (x1 <= 0) {
        analogWrite(x, 0);
      }
      if (y1 <= 0) {
        analogWrite(y, 0);
      }
    }
    if (bs == stamp2) {        // if the brightsign sends stamp2 (which is "2", see line 43), the following code happens- this should happen at the second timestamp marked in the audio on the brightsign
      while (abright != a2) {  // the following is almost the same as lines 57 through 81 except that it includes light b, as timestamp 2 is when b turns on, and the other lights turn off or change to a dimmer setting. this code repeats for the other lights in their own "while" sections, similar to the previous timestamp.
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright > a2) {  // this is one of the notable changes- if a is still MORE than the brightness goal, it will increase by the fadeAmount until it reaches the goal. this is opposite to the previous timestamp and will happen again at the media end. note that the "else" portion is the same as before- if a is already at its goal, the light will not change at all
          abright = abright - fadeAmount;
        } else {
          if (abright == a2) {
            abright = abright;
          }
        }
        if (bbright < b2) {  // if b is still less than the brightness goal, it will increase by the fadeAmount until it reaches the goal. if b is already at the goal, the light will not change at all
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright > x2) {  // this is one of the notable changes- if b is still MORE than the brightness goal, it will increase by the fadeAmount until it reaches the goal. this is opposite to the previous timestamp and will happen again at the media end. note that the "else" portion is the same as before- if b is already at its goal, the light will not change at all
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > y2) {  // this is one of the notable changes- if y is still MORE than the brightness goal, it will increase by the fadeAmount until it reaches the goal. this is opposite to the previous timestamp and will happen again at the media end. note that the "else" portion is the same as before- if y is already at its goal, the light will not change at all
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures a turns off fully if it's supposed to
        if (a2 <= 0) {
          analogWrite(a, 0);
        }
      }
      while (bbright != b2) {
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright > a2) {
          abright = abright - fadeAmount;
        } else {
          if (abright == a2) {
            abright = abright;
          }
        }
        if (bbright < b2) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright > x2) {
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > y2) {
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures b turns off fully if it's supposed to
        if (b2 <= 0) {
          analogWrite(b, 0);
        }
      }
      while (xbright != x2) {
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        if (abright > a2) {
          abright = abright - fadeAmount;
        } else {
          if (abright == a2) {
            abright = abright;
          }
        }
        if (bbright < b2) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright > x2) {
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > y2) {
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures x turns off fully if it's supposed to
        if (x2 <= 0) {
          analogWrite(x, 0);
        }
      }
      while (ybright != y2) {
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright > a2) {
          abright = abright - fadeAmount;
        } else {
          if (abright == a2) {
            abright = abright;
          }
        }
        if (bbright < b2) {
          bbright = bbright + fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright > x2) {
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > y2) {
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures y turns off fully if it's supposed to
        if (y2 <= 0) {
          analogWrite(y, 0);
        }
      }
      // ensures each light turns off fully if it's supposed to, just in case the above code misses it
      if (a2 <= 0) {
        analogWrite(a, 0);
      }
      if (b2 <= 0) {
        analogWrite(b, 0);
      }
      if (x2 <= 0) {
        analogWrite(x, 0);
      }
      if (y2 <= 0) {
        analogWrite(y, 0);
      }
    }
    if (bs == stamp3) {        // if the brightsign sends stamp3 (which is "3", see line 44), the following code happens- this should happen at the third timestamp marked in the audio on the brightsign
      while (abright != a3) {  // this is the same pattern as timestamp 1 except that it includes b
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright < a3) {
          abright = abright + fadeAmount;
        } else {
          if (abright == a3) {
            abright = abright;
          }
        }
        if (bbright > b3) {  // this is one of the notable changes- if b is still MORE than the brightness goal, it will increase by the fadeAmount until it reaches the goal. this is opposite to the previous timestamp and will happen again at the media end. note that the "else" portion is the same as before- if b is already at its goal, the light will not change at all
          bbright = bbright - fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright < x3) {  // this is the same as what happens to x in timestamp 1
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y3) {  // this is the same as what happens to y in timestamp 1
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures a turns off fully if it's supposed to
        if (a3 <= 0) {
          analogWrite(a, 0);
        }
      }
      while (bbright != b3) {
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright < a3) {
          abright = abright + fadeAmount;
        } else {
          if (abright == a3) {
            abright = abright;
          }
        }
        if (bbright > b3) {
          bbright = bbright - fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright < x3) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y3) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures b turns off fully if it's supposed to
        if (b3 <= 0) {
          analogWrite(b, 0);
        }
      }
      while (xbright != x3) {
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright < a3) {
          abright = abright + fadeAmount;
        } else {
          if (abright == a3) {
            abright = abright;
          }
        }
        if (bbright > b3) {
          bbright = bbright - fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright < x3) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y3) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures x turns off fully if it's supposed to
        if (x3 <= 0) {
          analogWrite(x, 0);
        }
      }
      while (ybright != y3) {
        analogWrite(a, abright);
        analogWrite(b, bbright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright < a3) {
          abright = abright + fadeAmount;
        } else {
          if (abright == a3) {
            abright = abright;
          }
        }
        if (bbright > b3) {
          bbright = bbright - fadeAmount;
        } else {
          bbright = bbright;
        }
        if (xbright < x3) {
          xbright = xbright + fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright < y3) {
          ybright = ybright + fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures y turns off fully if it's supposed to
        if (y3 <= 0) {
          analogWrite(y, 0);
        }
      }
      // ensures each light turns off fully if it's supposed to, just in case the above code misses it
      if (a3 <= 0) {
        analogWrite(a, 0);
      }
      if (b3 <= 0) {
        analogWrite(b, 0);
      }
      if (x3 <= 0) {
        analogWrite(x, 0);
      }
      if (y3 <= 0) {
        analogWrite(y, 0);
      }
    }
    if (bs == end) {  // if the brightsign sends end (which is "4", see line 45), the following code happens- this should happen at the end of the audio on the brightsign
      while (abright != aend) {
        analogWrite(a, abright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);  // b is excluded because it will never change between timestamp 3 and the end of the audio. otherwise, it has the same pattern as timestamp 2.
        // defines brightnesses
        if (abright > aend) {
          abright = abright - fadeAmount;
        } else {
          if (abright == aend) {
            abright = abright;
          }
        }
        if (xbright > xend) {
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > yend) {
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures a turns off fully if it's supposed to
        if (aend <= 0) {
          analogWrite(a, 0);
        }
      }
      while (xbright != xend) {
        analogWrite(a, abright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright > aend) {
          abright = abright - fadeAmount;
        } else {
          if (abright == aend) {
            abright = abright;
          }
        }
        if (xbright > xend) {
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > yend) {
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures x turns off fully if it's supposed to
        if (xend <= 0) {
          analogWrite(x, 0);
        }
      }
      while (ybright != yend) {
        analogWrite(a, abright);
        analogWrite(x, xbright);
        analogWrite(y, ybright);
        // defines brightnesses
        if (abright > aend) {
          abright = abright - fadeAmount;
        } else {
          if (abright == aend) {
            abright = abright;
          }
        }
        if (xbright > xend) {
          xbright = xbright - fadeAmount;
        } else {
          xbright = xbright;
        }
        if (ybright > yend) {
          ybright = ybright - fadeAmount;
        } else {
          ybright = ybright;
        }
        // wait to see the dimming effect- time is a const int established on line 17
        delay(time);
        // ensures y turns off fully if it's supposed to
        if (yend <= 0) {
          analogWrite(y, 0);
        }
      }
      // ensures each light turns off fully if it's supposed to, just in case the above code misses it
      if (aend <= 0) {
        analogWrite(a, 0);
      }
      if (xend <= 0) {
        analogWrite(x, 0);
      }
      if (yend <= 0) {
        analogWrite(y, 0);
      }
    }
  }
}

Thanks to everyone that helped!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.