OK, I've cleaned it up and set up separate sketches.
Task #1. Put the following 4 sketches together, toggled by a switch on pin TBD. While PIN_FL 6 and PIN_FR 7 are lit at (255)
//Fading Tail Lights
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
#define DELAY_TIME 10
// The pins which each color value is output to.
#define PIN_RED 9
#define PIN_RED2 10
// The initial values of each color.
int red = 20;
int red2 = 20;
// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incR2 = 1;
// Smoothly changes the color values
void transition()
{
if (red >= 175)
incR = 0;
else if (red <= 20)
incR = 1;
if (red2 >= 175)
incR2 = 0;
else if (red2 <= 20)
incR2 = 1;
if (incR)
red++;
else
red--;
if(incR2)
red2++;
else
red2--;
}
// Sets the output voltage on the LED pins.
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_RED2, red2);
}
void setup()
{
// Do nothing.
}
void loop()
{
transition();
setColor();
delay(DELAY_TIME);
}
//Fading Tail Lights 2
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
#define DELAY_TIME 5
// The pins which each color value is output to.
#define PIN_RED 9
#define PIN_RED2 10
// The initial values of each color.
int red = 175;
int red2 = 20;
// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incR2 = 1;
// Smoothly changes the color values
void transition()
{
if (red >= 175)
incR = 0;
else if (red <= 20)
incR = 1;
if (red2 >= 175)
incR2 = 0;
else if (red2 <= 20)
incR2 = 1;
if (incR)
red++;
else
red--;
if(incR2)
red2++;
else
red2--;
}
// Sets the output voltage on the LED pins.
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_RED2, red2);
}
void setup()
{
// Do nothing.
}
void loop()
{
transition();
setColor();
delay(DELAY_TIME);
}
//Fading Tail Lights 3
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
#define DELAY_TIME 2
// The pins which each color value is output to.
#define PIN_RED 9
#define PIN_RED2 10
// The initial values of each color.
int red = 175;
int red2 = 20;
// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incR2 = 1;
// Smoothly changes the color values
void transition()
{
if (red >= 175)
incR = 0;
else if (red <= 20)
incR = 1;
if (red2 >= 175)
incR2 = 0;
else if (red2 <= 20)
incR2 = 1;
if (incR)
red++;
else
red--;
if(incR2)
red2++;
else
red2--;
}
// Sets the output voltage on the LED pins.
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_RED2, red2);
}
void setup()
{
// Do nothing.
}
void loop()
{
transition();
setColor();
delay(DELAY_TIME);
}
//Fading Tail Lights 4
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
#define DELAY_TIME 1
// The pins which each color value is output to.
#define PIN_RED 9
#define PIN_RED2 10
// The initial values of each color.
int red = 20;
int red2 = 20;
// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incR2 = 1;
// Smoothly changes the color values
void transition()
{
if (red >= 175)
incR = 0;
else if (red <= 20)
incR = 1;
if (red2 >= 175)
incR2 = 0;
else if (red2 <= 20)
incR2 = 1;
if (incR)
red++;
else
red--;
if(incR2)
red2++;
else
red2--;
}
// Sets the output voltage on the LED pins.
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_RED2, red2);
}
void setup()
{
// Do nothing.
}
void loop()
{
transition();
setColor();
delay(DELAY_TIME);
}