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:

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