Multiple LED's on separate pins, switches and functions - need guidance

HolidayV:
Task #1. Put the following 4 sketches together, toggled by a switch on pin TBD.

So is the only difference between these 4 sketches the delay values and the initial values and directions for the 2 red leds?

HolidayV:
Task #3. Left and Right turn signals ONLY override the LEDs corresponding with that sketch.

And the only difference between these 2 sketches is the left vs right difference?

I like how you have broken the problem down. I suggest tackling merging the sketches in tasks #1 & 3 first. This should leave you with only 3 sketches to merge at the end.

If done correctly, that final merge should be really easy. Before that comes the more difficult task: Removing all the delay() commands from your 3 sketches! Read the "blink without delay" example, then have a go at just one of your 3 sketches. When that works without delays, work on the other two.

PaulRB:

HolidayV:
Task #1. Put the following 4 sketches together, toggled by a switch on pin TBD.

Yes, the first 4 are only change is delay values and initial values.
Yes, the only difference is left vs. Right.
I spent a good hour this morning trying to merge the two from task #3 this morning before I finally gave up. I spent over 6 hours last night/this morning just to get the above sketches to work separately.

So is the only difference between these 4 sketches the delay values and the initial values and directions for the 2 red leds?

HolidayV:
Task #3. Left and Right turn signals ONLY override the LEDs corresponding with that sketch.

And the only difference between these 2 sketches is the left vs right difference?

I like how you have broken the problem down. I suggest tackling merging the sketches in tasks #1 & 3 first. This should leave you with only 3 sketches to merge at the end.

If done correctly, that final merge should be really easy. Before that comes the more difficult task: Removing all the delay() commands from your 3 sketches! Read the "blink without delay" example, then have a go at just one of your 3 sketches. When that works without delays, work on the other two.

That was a confusing post!

Sounds like you are getting some learning done. Do you have something specific you need help with at this point?

Sorry, I put my reply in the middle of the two quotes. I'm trying to merge the 4 fading sketches into one, but I can't find an example that gives me the info that I need. I have managed to add FR and FL to the sketches so that the headlights are on constant while the tail lights are flashing. Unfortunately, I don't have arduino IDE on my work PC and I'm trying to work with Arduinodroid on my tablet but it keeps crashing on me every couple minutes. How do I set up the toggle switch if I run it off PIN 3 to toggle sketches 1,2,3,4 and then back to 1 with each press?

I have combined the left and right turn signals, but when I press the right turn button, it blinks the left turn signals before switching to the right signals. The left signals work just fine.

byte Right_Turn= 4 ; //Set Pin 4 as Switch
byte PIN_RED = 9;  //Right Rear Set Pin 9 as LED
byte PIN_FR = 7;  //Right Front Set Pin 7 as LED
byte Left_Turn= 5 ; //Set Pin 5 as Switch
byte PIN_RED2 = 10;  //Left Rear Set Pin 10 as LED
byte PIN_FL = 6;  //Left Front Set Pin 6 as LED
boolean buttonstate; //Integer variable named buttonstate
boolean button_state; //Integer variable named buttonstate


void setup()
{
  pinMode(Left_Turn, INPUT);
  pinMode(PIN_RED2, OUTPUT);
  pinMode(PIN_FL, OUTPUT);
  pinMode(Right_Turn, INPUT);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_FR, OUTPUT);
 
}
 
void loop()
{
buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
}
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
if (button_state == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
turnRight(); //new function called turnRight
}
}
 
void turnLeft()//turnLeft function 
{
buttonstate = HIGH; //the micro the switch is now HIGH

while (buttonstate == HIGH) //While the switch is NOT pressed do the following
{
buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
analogWrite(PIN_FL, 255); //Set the Front Left LED to maximum brightness
delay(100); 
analogWrite(PIN_RED2, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FL, 0); //turn the LED off for a blinking effect
delay(100);
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED2, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FL, 0); //We turn the LED off before leaving our custom function
}

void turnRight()//turnRight function 
{
button_state = HIGH; //the micro the switch is now HIGH

while (button_state == HIGH) //While the switch is NOT pressed do the following
{
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
analogWrite(PIN_FR, 255); //Set the Front Right LED to maximum brightness
delay(100); 
analogWrite(PIN_RED, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FR, 0); //turn the LED off for a blinking effect
delay(100);
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FR, 0); //We turn the LED off before leaving our custom function

}

Got the headlights lit and remaining lit during the turn signals but still have the Right switch, Left lights, problem

byte Right_Turn= 4 ; //Set Pin 4 as Switch
byte PIN_RED = 9;  //Right Rear Set Pin 9 as LED
byte PIN_FR = 7;  //Right Front Set Pin 7 as LED
byte Left_Turn= 5 ; //Set Pin 5 as Switch
byte PIN_RED2 = 10;  //Left Rear Set Pin 10 as LED
byte PIN_FL = 6;  //Left Front Set Pin 6 as LED
boolean buttonstate; //Integer variable named buttonstate
boolean button_state; //Integer variable named buttonstate


void setup()
{
  pinMode(Left_Turn, INPUT);
  pinMode(PIN_RED2, OUTPUT);
  pinMode(PIN_FL, OUTPUT);
  pinMode(Right_Turn, INPUT);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_FR, OUTPUT);
 
}
 
void loop()
{
 analogWrite(PIN_FR, 255);
 analogWrite(PIN_FL, 255);
buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
}
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
if (button_state == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
turnRight(); //new function called turnRight
}
}
 
void turnLeft()//turnLeft function 
{
  analogWrite(PIN_FR, 255);
buttonstate = HIGH; //the micro the switch is now HIGH

while (buttonstate == HIGH) //While the switch is NOT pressed do the following
{

buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
analogWrite(PIN_FL, 255); //Set the Front Left LED to maximum brightness
delay(100); 
analogWrite(PIN_RED2, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FL, 0); //turn the LED off for a blinking effect
delay(100);

}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED2, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FL, 0); //We turn the LED off before leaving our custom function
}

void turnRight()//turnRight function 
{
    analogWrite(PIN_FL, 255);
button_state = HIGH; //the micro the switch is now HIGH

while (button_state == HIGH) //While the switch is NOT pressed do the following
{
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
analogWrite(PIN_FR, 255); //Set the Front Right LED to maximum brightness
delay(100); 
analogWrite(PIN_RED, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FR, 0); //turn the LED off for a blinking effect
delay(100);
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FR, 0); //We turn the LED off before leaving our custom function

}

I think I'm starting to get the hang of this just a little. I now have the LEFT TURN, RIGHT TURN, and BRAKE LIGHTS merged along with keeping the headlights lit during the whole thing. While turning right, the left front stays lit while the right front and back flash, and vise versa. I still have the problem with the right button flashing the left lights before switching to the right lights but it's getting alot closer because I'm now down from 7 separate sketches to 5. Still have no idea how to merge the FADE sketches and toggle them. I think I could merge one of them into the existing sketch that I have now, but that's about as far as I'll be able to get.
Here's what I've got so far:

byte BRAKE_SWITCH = 8; //Set Pin 8 as Brake Switch
byte Right_Turn= 4; //Set Pin 4 as Switch
byte PIN_RED = 9;  //Right Rear Set Pin 9 as LED
byte PIN_FR = 7;  //Right Front Set Pin 7 as LED
byte Left_Turn = 5 ; //Set Pin 5 as Switch
byte PIN_RED2 = 10;  //Left Rear Set Pin 10 as LED
byte PIN_FL = 6;  //Left Front Set Pin 6 as LED
boolean buttonstate; //Integer variable named buttonstate Left Turn Switch
boolean button_state; //Integer variable named button_state Right Turn Switch
boolean button__state; //Integer variable named button__state Brake Switch


void setup()
{
  pinMode(Left_Turn, INPUT);
  pinMode(PIN_RED2, OUTPUT);
  pinMode(PIN_FL, OUTPUT);
  pinMode(Right_Turn, INPUT);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_FR, OUTPUT);
  pinMode(BRAKE_SWITCH, INPUT);
}
 
void loop()
{
 analogWrite(PIN_FR, 255);
 analogWrite(PIN_FL, 255);
 
button__state = digitalRead(BRAKE_SWITCH); //Continually look at the switch to see if its pressed
if (button__state == HIGH) //If the switch goes HIGH, act on it
{
  brakelights(); //new function called brakelights
}
  
buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
}
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
if (button_state == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
turnRight(); //new function called turnRight
brakelights(); //new function called brakelights
}
}
 
void turnLeft()//turnLeft function 
{
  analogWrite(PIN_FR, 255);
buttonstate = HIGH; //the micro the switch is now HIGH

while (buttonstate == HIGH) //While the switch is NOT pressed do the following
{

buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
analogWrite(PIN_FL, 255); //Set the Front Left LED to maximum brightness
delay(100); 
analogWrite(PIN_RED2, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FL, 0); //turn the LED off for a blinking effect
delay(100);

}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED2, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FL, 0); //We turn the LED off before leaving our custom function
}

void turnRight()//turnRight function 
{
    analogWrite(PIN_FL, 255);
button_state = HIGH; //the micro the switch is now HIGH

while (button_state == HIGH) //While the switch is NOT pressed do the following
{
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
analogWrite(PIN_FR, 255); //Set the Front Right LED to maximum brightness
delay(100); 
analogWrite(PIN_RED, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FR, 0); //turn the LED off for a blinking effect
delay(100);
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FR, 0); //We turn the LED off before leaving our custom function
}

void brakelights()
{

analogWrite(PIN_FL, 255);
analogWrite(PIN_FR, 255);
button__state = HIGH; //the micro switch is now HIGH

while (button__state == HIGH) //While the switch is NOT pressed do the following
{
  button__state = digitalRead(BRAKE_SWITCH); //Continually look at the switch to see if its pressed
  analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
  analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
  
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_RED2, 0); //We turn the LED off before leaving our custom function
}

HolidayV:
I still have the problem with the right button flashing the left lights before switching to the right lights

button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed

if (button_state == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
turnRight(); //new function called turnRight
brakelights(); //new function called brakelights
}

Why are you calling the turnLeft() and brakelights() functions when the Right_Turn button is pressed?

Because I apparently, subconsciously, want to have the left turn signals to flash when I press the right turn button :roll_eyes: I'll have to fix that. Any ideas on merging the fade sketches?

Certainly!

We agreed earlier that the only differences between the 4 sketches were the initial levels of the 2 red leds, the directions, and the length of the delay between updates.

  • You will need a new global variable to keep track of which of the 4 patterns is currently running. This can take values 0, 1, 2 or 3.
  • You want to move to the next pattern only when the applicable button changes from being not pressed to being pressed (or alternatively vice versa if you like). You don't want to be continually moving to the next pattern over and over all the while the button is pressed. Switch bouncing may well be an issue, lets see what happens and deal if necessary.
  • Each time the pattern is changed, you want to set the initial levels, directions and delay for that new pattern. See the switch case command.

Hope this helps.

Paul

PaulRB:
You will need a new global variable to keep track of which of the 4 patterns is currently running. This can take values 0, 1, 2 or 3.

How do I do that? I've spent two hours trying to figure it out to no avail. :blush:

Once I know, I think I can figure it out from there.

Exactly as you did for your other global variables "red", "red2", "white", "incR" and "incR2".

What makes them "global" is that they are declared at the top of the sketch, outside of any function. This means they can be seen and changed by any function. If they were declared inside a function, they would be "local" and only visible within that function, and (normally) their value would be lost when the function finished executing.

PaulRB:
Exactly as you did for your other global variables "red", "red2", "white", "incR" and "incR2".

What makes them "global" is that they are declared at the top of the sketch, outside of any function. This means they can be seen and changed by any function. If they were declared inside a function, they would be "local" and only visible within that function, and (normally) their value would be lost when the function finished executing.

I'm still not quite understanding how to do it. All the examples I've seen on the caseswitch command involve serial or potentiometer, or LDR inputs where the case is a definable read value, but in this instance I'm reading a function, because red, and red2 are fading and constantly changing output value and I need to know which function's starting point they started at. While I can certainly appreciate how your non specific answers have helped me down the path of learning, some example code to help me tie this all together would be greatly appreciated.

OK, here are some suggested (and untested) code fragments:

int currentPattern = 4;
int patternButtonState = HIGH;
unsigned long delayTime = 50;

Note I have assumed the button to change pattern is normally LOW and you have a pull-down resistor on the input to prevent if from floating. This patternButtonState variable is set initially to HIGH, but as soon as the sketch starts running and detects the button state is LOW, it will act as though the button has just been released and set up the first flashing pattern.

  if (digitalRead(patternButton) != patternButtonState)  { //the button state has changed

    if (patternButtonState == LOW) { //the button state must have just gone high
      patternButtonState = HIGH;  //record that button has just been pressed but do nothing for now, wait for release

    else { //it was high, so the button must have just been released

      //record the fact that be button has now gone low ie. not pressed
      patternButtonState = LOW;

      switch (currentPattern) {

        case 1: //Pattern 1 has been running
          //set up pattern 2
          currentPattern = 2;
          red = ...;
          red2 = ...;
          incR = ...;
          incR2 = ...;
          delayTime = ...;
          break;

        case 2:
          ...

        case 3:
          ...

        case 4:
          //set up pattern 1
          currentPattern = 1;
          red = ...;
          red2 = ...;
          incR = ...;
          incR2 = ...;
          delayTime = ...;
          break;

      }
    }

Hope this makes at least some sense!

Paul

Well, it looked like it would work. But, I probably screwed it up entering into the existing code.

byte BRAKE_SWITCH = 8; //Set Pin 8 as Brake Switch
byte Right_Turn= 4; //Set Pin 4 as Switch
byte PIN_RED = 11;  //Right Rear Set Pin 11 as LED
byte PIN_FR = 7;  //Right Front Set Pin 7 as LED
byte Left_Turn = 5 ; //Set Pin 5 as Switch
byte PIN_RED2 = 10;  //Left Rear Set Pin 10 as LED
byte PIN_FL = 6;  //Left Front Set Pin 6 as LED
byte PIN_TOGG = 2; //Toggle Fades set Pin 2
boolean buttonstate; //Integer variable named buttonstate Left Turn Switch
boolean button_state; //Integer variable named button_state Right Turn Switch
boolean button__state; //Integer variable named button__state Brake Switch

// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
unsigned long delayTime = 10;

int currentPattern = 4;
int patternButtonState = HIGH;

// 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;



void setup()
{
  
  pinMode(PIN_TOGG, INPUT);
  pinMode(Left_Turn, INPUT);
  pinMode(PIN_RED2, OUTPUT);
  pinMode(PIN_FL, OUTPUT);
  pinMode(Right_Turn, INPUT);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_FR, OUTPUT);
  pinMode(BRAKE_SWITCH, INPUT);
}
 
void turnLeft()//turnLeft function 
{
  analogWrite(PIN_FR, 255);
  analogWrite(PIN_RED, 125); 
analogWrite(PIN_RED2, 125);
buttonstate = HIGH; //the micro the switch is now HIGH

while (buttonstate == HIGH) //While the switch is NOT pressed do the following
{

buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
analogWrite(PIN_FL, 255); //Set the Front Left LED to maximum brightness
delay(100); 
analogWrite(PIN_RED2, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FL, 0); //turn the LED off for a blinking effect
delay(100);

}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED2, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FL, 0); //We turn the LED off before leaving our custom function
}

void turnRight()//turnRight function 
{
    analogWrite(PIN_FL, 255);
    analogWrite(PIN_RED, 125); 
analogWrite(PIN_RED2, 125);
button_state = HIGH; //the micro the switch is now HIGH

while (button_state == HIGH) //While the switch is NOT pressed do the following
{
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
analogWrite(PIN_FR, 255); //Set the Front Right LED to maximum brightness
delay(100); 
analogWrite(PIN_RED, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FR, 0); //turn the LED off for a blinking effect
delay(100);
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FR, 0); //We turn the LED off before leaving our custom function
}

void brakelights()
{

analogWrite(PIN_FL, 255);
analogWrite(PIN_FR, 255);
button__state = HIGH; //the micro switch is now HIGH

while (button__state == HIGH) //While the switch is NOT pressed do the following
{
  button__state = digitalRead(BRAKE_SWITCH); //Continually look at the switch to see if its pressed
  analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
  analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
  
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 125); //We turn the LED off before leaving our custom function
analogWrite(PIN_RED2, 125); //We turn the LED off before leaving our custom function
}

// 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 loop()
{
 analogWrite(PIN_FR, 255);
 analogWrite(PIN_FL, 255);
  transition();
  setColor();
  delay(delayTime);
  
  button__state = digitalRead(BRAKE_SWITCH); //Continually look at the switch to see if its pressed
if (button__state == HIGH) //If the switch goes HIGH, act on it
{
  brakelights(); //new function called brakelights
}
  
buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
}
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
if (button_state == HIGH) //If the switch goes HIGH, act on it
{

turnRight(); //new function called turnRight

}
  
  if (digitalRead(PIN_TOGG) != patternButtonState)  { //the button state has changed

    if (patternButtonState == LOW) { //the button state must have just gone high
      patternButtonState = HIGH;  //record that button has just been pressed but do nothing for now, wait for release
    }
    else { //it was high, so the button must have just been released

      //record the fact that be button has now gone low ie. not pressed
      patternButtonState = LOW;

      switch (currentPattern) {

        case 1: //Pattern 1 has been running
          //set up pattern 2
          currentPattern = 2;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 5;
          break;

        case 2://Pattern 2 has been running
          //set up pattern 3
          currentPattern = 3;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 2;

        case 3://Pattern 3 has been running
          //set up pattern 4
          currentPattern = 4;
          red = 20;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 1;

        case 4:
          //set up pattern 1
          currentPattern = 1;
          red = 20;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 10;
          break;


      }
    }
  }
}

It really helps when you have the toggling switch plugged into pin 3 but set it to pin 2. The code is working with exception of the delay time on the patterns is not changing.

I tinkered with the code, and added a couple more cases. Now I have 7 in total but the funny thing is, it's only outputting 5?

digitalRead(PIN_TOGG);
  if (digitalRead(PIN_TOGG) != patternButtonState)  { //the button state has changed

    if (patternButtonState == LOW) { //the button state must have just gone high
      patternButtonState = HIGH;  //record that button has just been pressed but do nothing for now, wait for release
    }
    else { //it was high, so the button must have just been released

      //record the fact that be button has now gone low ie. not pressed
      patternButtonState = LOW;

      switch (currentPattern) {

case 1: //Pattern 1 has been running
          //set up pattern 2
          currentPattern = 2;
          red = 175;
          red2 = 175;
          incR = 1;
          incR2 = 1;
          delayTime = 5;
          break;

case 2://Pattern 2 has been running
          //set up pattern 3
          currentPattern = 3;
          red = 175;
          red2 = 175;
          incR = 1;
          incR2 = 1;
          delayTime = 1;

case 3://Pattern 3 has been running
          //set up pattern 4
          currentPattern = 4;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 10;

case 4://Pattern 4 has been running
          //set up pattern 5
          currentPattern = 5;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 5;
          break;
          
case 5://Pattern 5 has been running
          //set up pattern 6
          currentPattern = 6;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 1;
          break;
          
case 6://Pattern 6 has been running
          //set up pattern 7
          currentPattern = 7;
          red = 175;
          red2 = 175;
          incR = 0;
          incR2 = 0;
          delayTime = 0;
          break;
          
case 7:
          //set up pattern 1
          currentPattern = 1;
          red = 175;
          red2 = 175;
          incR = 1;
          incR2 = 1;
          delayTime = 10;
          break;
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
unsigned long delayTime = 10;

int currentPattern = 7;
int patternButtonState = HIGH;

// The initial values of each color.
int red = 175;
int red2 = 175;

// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incR2 = 1;

You need a "break;" for each "case". There are 2 missing.

Ahhhh! That probably happened with copy and paste. I'll check it tonight when I get home. Thank you so much for all your help on this. You are awesome.

It WORKS!!! HOORAY!!!

Here's the working code if anybody wants it:

//////Bicycle Light System v1.0////////////

/////Author: Christopher Valentine 2014
/////Special Thanks to: PaulRB of the Arduino support forum!!!

////This is a full blown bicyle light system with 
////headlights, turn signals (front and back), 
////brakelights, and multi-function flashing tail lights
////Although this set up is designed for a bike,
////with the use of a wireless remote control it could 
////Also be used on a remote control car or other things


byte BRAKE_SWITCH = 8; //Set Pin 8 as Brake Switch
byte Right_Turn= 4; //Set Pin 4 as Switch
byte PIN_RED = 11;  //Right Rear Set Pin 11 as LED
byte PIN_FR = 7;  //Right Front Set Pin 7 as LED
byte Left_Turn = 5 ; //Set Pin 5 as Switch
byte PIN_RED2 = 10;  //Left Rear Set Pin 10 as LED
byte PIN_FL = 6;  //Left Front Set Pin 6 as LED
byte PIN_TOGG = 3; //Toggle Fades set Pin 3
boolean buttonstate; //Integer variable named buttonstate Left Turn Switch
boolean button_state; //Integer variable named button_state Right Turn Switch
boolean button__state; //Integer variable named button__state Brake Switch

// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
unsigned long delayTime = 10;

int currentPattern = 7;
int patternButtonState = HIGH;

// The initial values of each color.
int red = 175;
int red2 = 175;

// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incR2 = 1;

void setup()
{
  pinMode(PIN_TOGG, INPUT);
  pinMode(Left_Turn, INPUT);
  pinMode(PIN_RED2, OUTPUT);
  pinMode(PIN_FL, OUTPUT);
  pinMode(Right_Turn, INPUT);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_FR, OUTPUT);
  pinMode(BRAKE_SWITCH, INPUT);
}
 
void turnLeft()//turnLeft function 
{
analogWrite(PIN_FR, 255);
analogWrite(PIN_RED, 125); 
analogWrite(PIN_RED2, 125);
buttonstate = HIGH; //the micro the switch is now HIGH

while (buttonstate == HIGH) //While the switch is NOT pressed do the following
{

buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
analogWrite(PIN_FL, 255); //Set the Front Left LED to maximum brightness
delay(100); 
analogWrite(PIN_RED2, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FL, 0); //turn the LED off for a blinking effect
delay(100);

}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED2, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FL, 0); //We turn the LED off before leaving our custom function
}

void turnRight()//turnRight function 
{
analogWrite(PIN_FL, 255);
analogWrite(PIN_RED, 125); 
analogWrite(PIN_RED2, 125);
button_state = HIGH; //the micro the switch is now HIGH

while (button_state == HIGH) //While the switch is NOT pressed do the following
{
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
analogWrite(PIN_FR, 255); //Set the Front Right LED to maximum brightness
delay(100); 
analogWrite(PIN_RED, 0); //turn the LED off for a blinking effect
analogWrite(PIN_FR, 0); //turn the LED off for a blinking effect
delay(100);
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 0); //We turn the LED off before leaving our custom function
analogWrite(PIN_FR, 0); //We turn the LED off before leaving our custom function
}

void brakelights()
{

analogWrite(PIN_FL, 255);
analogWrite(PIN_FR, 255);
button__state = HIGH; //the micro switch is now HIGH

while (button__state == HIGH) //While the switch is NOT pressed do the following
{
  button__state = digitalRead(BRAKE_SWITCH); //Continually look at the switch to see if its pressed
  analogWrite(PIN_RED, 255); //Set the Rear Right LED to maximum brightness
  analogWrite(PIN_RED2, 255); //Set the Rear Left LED to maximum brightness
  
}
//Once the switch is pressed again, break out of the loop above and then break out of the function completely and go back to our main loop
button_state = LOW; //First we tell the micro the switch is now LOW
analogWrite(PIN_RED, 125); //We turn the LED off before leaving our custom function
analogWrite(PIN_RED2, 125); //We turn the LED off before leaving our custom function
}

// 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 loop()
{
 analogWrite(PIN_FR, 255);
 analogWrite(PIN_FL, 255);
 transition();
 setColor();
 delay(delayTime);
  
 button__state = digitalRead(BRAKE_SWITCH); //Continually look at the switch to see if its pressed
if (button__state == HIGH) //If the switch goes HIGH, act on it
{
  brakelights(); //new function called brakelights
}
  
buttonstate = digitalRead(Left_Turn); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
{
turnLeft(); //new function called turnLeft
}
button_state = digitalRead(Right_Turn); //Continually look at the switch to see if its pressed
if (button_state == HIGH) //If the switch goes HIGH, act on it
{
turnRight(); //new function called turnRight
}

digitalRead(PIN_TOGG);
  if (digitalRead(PIN_TOGG) != patternButtonState)  { //the button state has changed

    if (patternButtonState == LOW) { //the button state must have just gone high
      patternButtonState = HIGH;  //record that button has just been pressed but do nothing for now, wait for release
    }
    else { //it was high, so the button must have just been released

      //record the fact that be button has now gone low ie. not pressed
      patternButtonState = LOW;

      switch (currentPattern) {

case 1: //Pattern 1 has been running
          //set up pattern 2
          currentPattern = 2;
          red = 175;
          red2 = 175;
          incR = 1;
          incR2 = 1;
          delayTime = 5;
          break;

case 2://Pattern 2 has been running
          //set up pattern 3
          currentPattern = 3;
          red = 175;
          red2 = 175;
          incR = 1;
          incR2 = 1;
          delayTime = 1;
          break;

case 3://Pattern 3 has been running
          //set up pattern 4
          currentPattern = 4;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 10;
          break;

case 4://Pattern 4 has been running
          //set up pattern 5
          currentPattern = 5;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 5;
          break;
          
case 5://Pattern 5 has been running
          //set up pattern 6
          currentPattern = 6;
          red = 175;
          red2 = 20;
          incR = 1;
          incR2 = 1;
          delayTime = 1;
          break;
          
case 6://Pattern 6 has been running
          //set up pattern 7
          currentPattern = 7;
          red = 175;
          red2 = 175;
          incR = 0;
          incR2 = 0;
          delayTime = 0;
          break;
          
case 7:
          //set up pattern 1
          currentPattern = 1;
          red = 175;
          red2 = 175;
          incR = 1;
          incR2 = 1;
          delayTime = 10;
          break;

      }
    }
  }
}