[ASSISTANCE] If statements with debounce and conditions

Hi there.

I need some help. I have completed the first two parts of my code blocks, tested it and all works fine, it is the last block of code I just cannot figure out where I am doing it wrong.

First the scope and some details:

I use internal Pull-up resistors with all switches.
ON-OFF-ON toggle switch, connected to Pins 3 and 4 (togglePin1 and togglePin2 respectively).
A momentary push button connected to Pin 2.

I have three conditions which are selected via an ON-OFF-ON toggle switch. The "first" on position is my "automatic" position where I cycle a 220VAC light bulb ON and OFF at 30 second intervals. (BTW, this was the initial scope, I wanted to add the three conditions). This condition, the "automatic" condition works a charm. For this condition I check via an IF statement whether togglePin1 is LOW, and togglePin2 is HIGH. I used a modified version of BlinkWithoutDelay since I want to check often if the toggle switch has been switched to OFF or the other ON.

Next, I have a "Nothing" condition. In this condition, nothing happens except the statusLed (pin 13) flashing. Here I check via an IF statement whether togglePin1 is HIGH and togglePin2 is HIGH. Again, works a charm. Again I used the BlinkWithoutDelay code for same reason as above.

The third mode I call "Trigger" mode. This condition leaves the light bulb off (led pin 12 at LOW) and waits for the push button to be pressed. I used the Debounce code to ensure that noise doesn't untrigger the cycling of the ON-OFF of the light bulb. This is my trouble code block that I cannot figure out.

I started this entire code thinking of using WHILE statements but couldn't get the IF statement to work with the pushbutton. Then I moved on to the multiple condition IF statements that include the timing for the BlinkWithoutDelay code. But I just cannot get the last bit to work. I have now split the last code block in two bits - first read the push button. Then I check via IF statement if togglePin1 is HIGH, and togglePin2 is LOW and if the debounce condition is met - meaning the pushbutton was pressed and it was not noise. Then I reset the pushbutton condition, change a the state of lightCycle from false to true. Then I proceed to the next if statement that, if the light cycle is true start with the bit of code that switches the light bulb ON-OFF. After that bit, there is another bit of code that checks again about the toggleswitch, and the puch button, and whether the lightCycle is true in order to change the lightCycle to false and switch off outputPin 12 - stopping the ON-OFF cycle.

Hope that makes sense, I've been sitting with it for the last 4 hours rewriting from my first code concept until this bit.

How do I do this last code block? How do I check the condition, plus check for a push button press without noise (debounce), start the lightCycle, and stop the lightCycle with another push button press all within the same toggleswitch condition. Currently, nothing happens. I've had it that the LED on pin 13 just flashes to just staying on, to I cannot remember all the other things that happened. I really want this last bit finished before this weekend Friday when I need to hand this project to the person I'm building it for. The basis blink sketch will do fine, but I really want this extra features for coolness and since I challenged myself with it. And I figured out a lot up until now that I am amazed with.

I do realise I can really stop and start the process with the toggle switch, but I like the idea of a push button trigger cause it is cooler and more ergonomic.

First, below my completed and tested bit of code with the "nothing" and "automatic" conditions.

Then the code block I just cannot figure out.

Completed code:

/*_________________Description & Scope______________________________________
This little program controls a incandescent light bulb for an exhibition
at a local church one of our friends go to. The initial design was merely 
switching the light bulb on and off at 30 second intervals. 
However, in conversation with my mate, we thought it will be nice to have
the option of triggering the cycle by means of a button. I decided to take
it one step further and provide three "modes" which are: 
  - Nothing: The light bulb is off with only a status light
  - Automatic: The light bulb cycles indefinitly with no control except by
                using the mode change switch
  - Trigger: A push button triggers the start/stop of the cycle.

Although the "mode" switch can do the triggering of the cycle, which is a 
ON-OFF-ON toggle switch, I think it is much more ergonomic to have a nice 
red momentary push button to be the trigger switch. Plus it looks cooler.

The installation was temporary and as such I used my Seeeduino board v2.21

I used internal pull-up resistors cause its convenient and from past
experience, although I could be wrong, I have found that reading a HIGH
can cause false triggers since even static from my finger can cause noise
on the input pin, hence I now always pull-up to HIGH and read a LOW signal.

Critical parts used:
  - BT139 600C TRIAC to switch the 220VAC and small heatsink for "coolness"
  - MOS3022 Optocoupler to isolate the digital signals from the AC circuit
  - ON-OFF-ON Toggle Switch
  - Momentary Push Button switch
  - Terminal Blocks
  - ACDC Adapter set output of 9V DC as power source, wired into 
    input AC circuit
    
             ===========================================
             =               IMPORTANT!                =
             =   Do NOT touch the heat sink or back    =
             =   of the TRIAC when connected to AC     =
             =     because the AC source lead is       =
             =  connected to it. In other words, you   =
             =         WILL GET ELECTROCUTED!          =
             =========================================== 
             

*/

/*___________________________Global Declarations________________________*/
const int togglePin1 = 3;
const int togglePin2 = 4;
const int buttonPin = 2;
const int statusPin = 13;
const int gatePin = 12;
int ledState = LOW;
int gateState = LOW;
long gateInterval = 3000;
long statusInterval = 500;
long previousMillis = 0;
long preGateMillis = 0;





/*_______________________________void setup_____________________________*/
void setup() {
  pinMode(togglePin1, INPUT);
  pinMode(togglePin2, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(statusPin, OUTPUT);
  pinMode(gatePin,OUTPUT);
  digitalWrite(togglePin1, HIGH);
  digitalWrite(togglePin2, HIGH);
  digitalWrite(buttonPin, HIGH);
  digitalWrite(statusPin, LOW);
  digitalWrite(gatePin, LOW);
  
}

void loop() {

/*__________________________IF nothing mode___________________________
When the toggle switch is in the OFF position, Nothing mode is engaged. 
Nothing mode has a status LED that blinks.
*/
  unsigned long statusMillis = millis();
 
  if(statusMillis - previousMillis > statusInterval)
  if (digitalRead(togglePin1) == HIGH 
   && digitalRead(togglePin2) == HIGH) 
     {
      digitalWrite(gatePin, LOW);
      previousMillis = statusMillis;   
        if (ledState == LOW)
          ledState = HIGH;
        else
          ledState = LOW;
      digitalWrite(statusPin, ledState);
    }

/*__________________________IF automatic mode_______________________
When the toggle switch points downwards, Automatic mode is engaged. I check
for a OFF and ON condition of the toggle switch.
*/
 
  unsigned long gateMillis = millis();
 
  if(gateMillis - preGateMillis > gateInterval
  && digitalRead(togglePin1) == LOW
  && digitalRead(togglePin2) == HIGH) 
  {
    preGateMillis = gateMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(statusPin, ledState);
    
    if (gateState == LOW)
      gateState = HIGH;
    else
      gateState = LOW;
    digitalWrite(gatePin, gateState);
  }

/*__________________________IF trigger mode_________________________
When the toggle switch points upwards, Automatic mode is engaged. I check
for a ON and OFF condition of the toggle switch.
*/

}

And the block of code I cannot break, my Trigger condition:

const int buttonPin = 2;     
const int ledPin =  13;      
const int togglePin1 = 3;
const int togglePin2 = 4;

int ledState = LOW;         
int buttonState;             
int lastButtonState = HIGH;   
int lightCycle;

long lastDebounceTime = 0;  
long debounceDelay = 50;    
long previousMillis = 0;
long statusInterval = 500;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(togglePin1, INPUT);
  pinMode(togglePin2, INPUT);
  digitalWrite(togglePin1, HIGH);
  digitalWrite(togglePin2, HIGH);
  pinMode(ledPin, OUTPUT);
  int lightCycle = false;
}

void loop() {

  int reading = digitalRead(buttonPin);
  
  if(reading != lastButtonState){
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay
    && digitalRead(togglePin1) == HIGH
    && digitalRead(togglePin2) == LOW
    && lightCycle == false) 
    {
    lightCycle == true;
    buttonState = reading;
    }
    lastButtonState = reading; 
    
   unsigned long statusMillis = millis();
  if (lightCycle == true)
    if(statusMillis - previousMillis > statusInterval)
    {
    previousMillis = statusMillis;   
        if (ledState == LOW)
          ledState = HIGH;
        else
          ledState = LOW;
      
      digitalWrite(ledPin, ledState);
    }

 
 
   if((millis() - lastDebounceTime) > debounceDelay
   && digitalRead(togglePin1) == HIGH
   && digitalRead(togglePin2) == LOW
   && lightCycle == true)
    {
      lightCycle == false;
      buttonState = reading;
      digitalWrite(ledPin, LOW);
    }
lastButtonState = reading;
}

Thank you for the help.

P.S. My Trigger mode code block is a new sketch. I am doing it as a new sketch until I have it sorted, then I build it into my final code - hence the fact use see global declarations again.

        if (ledState == LOW)
          ledState = HIGH;
        else
          ledState = LOW;

could be

        ledState = !ledState;

75% less code is usually a good thing. This happens in two other places in the first post.

  if(statusMillis - previousMillis > statusInterval)
  if (digitalRead(togglePin1) == HIGH

I really hate to see two if statements in a row with no { in between.

The uneven indenting and indented braces make blocks of code difficult to pick out. Perhaps more functions are in your future.

Thanks for the advice PaulS especially the shorter way of coding.. I looked at the formatting of my code in haste since I wasn't quite finished yet, however I wasn't sure either how to format double IF statements.

Here's an issue:

    {
    lightCycle == true;
    buttonState = reading;
    }

== used where you want =. Same issue further down too. It also seems a bit complex. One possible simplification would be to check the toggleswitches once and then wrap all the other code inside an if they control - i.e. you don't care about the momentary switch at all unless the toggle is set appropriately. Putting that code in its own function might make matters easier when you reintegrate it with the original sketch.

I can't figure it out.... :~ Thanks wildBill. I rewrote the code a bit, wrapping each mode in a status IF statement, but the pushbutton is just above me. For now I just made the "Trigger" mode blank mode.

What happens now is that in my "Trigger" mode, my status LED starts flashing without any input. Then after some more wrestling, I got it to stay off until I press the push button, but I couldn't figure out how to get it to stop....I think it has to do with my pushbutton state reset.

Then I thought (but that was 23:00 already) maybe I should use a latching code for a momentary push button, but I couldn't find a simple example (searching via google) code to insert which won't take too much of my time to figure out.

I'll wrestle some more with this code when I get my electronics back cause, I am preparing for it to be fetched tomorrow, but I actually am not sure when exactly they need it except for this weekend. :slight_smile:

Thank you for the help, unfortunately time got the better of me and work kept me busy enough not to start sooner.

If anyone has some more thoughts I am all ears....or rather eyes.

My new code, basically where I stopped - haven't gone with the simpler IF statements PaulS, had to try and figure out my trigger mode first, will clean up after words. :

/*___________________________Global Declarations________________________*/
const int togglePin1 = 3;
const int togglePin2 = 4;
const int buttonPin = 2;
const int statusPin = 13;
const int gatePin = 12;
int ledState = LOW;
long statusInterval = 500;
long previousMillis = 0;
int buttonState = 0; 
int lastButtonState = HIGH;
long lastDebounceTime = 0;
long debounceDelay = 50;
int cycleStatus;


/*_______________________________void setup_____________________________*/
void setup() {
  pinMode(togglePin1, INPUT);
  pinMode(togglePin2, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(statusPin, OUTPUT);
  pinMode(gatePin,OUTPUT);
  digitalWrite(togglePin1, HIGH);
  digitalWrite(togglePin2, HIGH);
  digitalWrite(buttonPin, HIGH);
  digitalWrite(statusPin, LOW);
  digitalWrite(gatePin, LOW);
  
}

void loop() {

/*__________________________IF nothing mode___________________________
When the toggle switch is in the OFF position, Nothing mode is engaged. 
Nothing mode has a status LED that blinks.
*/
  
  while (digitalRead(togglePin1) == HIGH 
     && digitalRead(togglePin2) == HIGH){
  
        unsigned long statusMillis = millis();
        
        if(statusMillis - previousMillis > statusInterval){
            
            if (ledState == LOW)
                ledState = HIGH;
            else
              ledState = LOW;
              
        previousMillis = statusMillis;
        
        digitalWrite(statusPin, ledState);
     }  
    }
/*__________________________IF automatic mode_______________________
When the toggle switch points downwards, Automatic mode is engaged.
*/
 
  while (digitalRead(togglePin1) == LOW 
     && digitalRead(togglePin2) == HIGH){
  
        unsigned long statusMillis = millis();
        
        if(statusMillis - previousMillis > statusInterval){
            
            if (ledState == LOW)
                ledState = HIGH;
            else
              ledState = LOW;
              
        previousMillis = statusMillis;
        
        digitalWrite(statusPin, ledState);
        digitalWrite(gatePin, ledState);
     }  
    } 


/*__________________________IF trigger mode_________________________
When the toggle switch points downwards, Automatic mode is engaged.
*/
  while (digitalRead(togglePin1) == HIGH 
     && digitalRead(togglePin2) == LOW){
  
        unsigned long statusMillis = millis();
        buttonState = digitalRead(buttonPin);
        
        if (buttonState != lastButtonState){
          if (buttonState == LOW){
       
          if(statusMillis - previousMillis > statusInterval){
            
            if (ledState == LOW)
                ledState = HIGH;
            else
              ledState = LOW;
              
        previousMillis = statusMillis;
        
        digitalWrite(statusPin, ledState);
        digitalWrite(gatePin, ledState);
          }
        }
        else {
          digitalWrite(statusPin, LOW);
          digitalWrite(gatePin, LOW);
        }
        
        
        } 
     lastButtonState = buttonState;
     }
        
        
        }

In trigger mode, you need to separate the led flashing from the button pressing. For the button press you can largely use the code you have: If the button state changed and if button state is low, delay 20 ms for debounce, then toggle a new state variable such as FlashLed.

FlashLed will flip between true and false every time you press the button. Still in the trigger mode code, if FlashLed is true execute your timed flashing logic, otherwise set the led off.

As you have it, the flashing logic only runs if there was a transition to low, so you have to keep pressing the button to permit the flash. Lack of debounce muddies the waters too.

Finally, those while loops can all be ifs, although I'd be tempted to read the inputs once, figure out what mode the system is in and use a switch statement to execute the approriate code.

Hey wildBill. I got a bit jaded last night regarding that trigger mode cause I kind of redid my other blocks of code - albeit not the simpler IF bits as mentioned by PaulS, and then I started playing with WHILE statements out of sheer frustration, even though I knew it was much of a muchness. I know it was something silly that I'm missing or just not doing - well silly in terms of logic.

Right let me see if I understand the logic behind this...seems I found out they will fetch it tomorrow mid day somewhere.

In my trigger mode. First I need to check if the mode is...or let me rather say it this way since I tried writing it out in sentences and that got messy.

Look for modes (Nothing mode, Automatic mode, Trigger mode - done with IF conditions based on my toggle switch position)
IF Trigger mode is true
Look for a button press (using Debounce to eliminate noise)
IF button has been pressed
Look for cycleStatus
IF cycleStatus is False and button press has happened
Start cycleStatus
If cycleStatus is TRUE and button press has happened
Stop cycleStatus

In other words (which I tried last night but just couldn't get right) each mode has this same logic, only my Trigger mode has an additional condition checking inside the Mode itself, that of checking if the button has been pressed.

How is code read in the Arduino....top to button always in the void Loop? I'm sure I had a link to that explanation somewhere.........(click click click searching click click searching)

Thanks for the help wildBill. I shall try again after work.

Right, I updated my code to what I think must/should work. Only I now found an anomaly. In Nothing mode, if I switch over to Trigger mode as pin13 is HIGH (as the LED on pin 13 is HIGH), then pin13 stays on for it seems forever. If I switch from Nothing mode to Trigger mode just as pin13 is LOW, then pin13 flashes momentarily at the interval time time (on flash then off at interval time).

So...what have I done wrong this time? EDIT: Rather...I obviously need to learn some more!

/*___________________________Global Declarations________________________*/
const int togglePin1 = 3;
const int togglePin2 = 4;
const int buttonPin = 2;
const int statusPin = 13;
const int gatePin = 12;
int ledState = LOW;
long statusInterval = 500;
long previousMillis = 0;
int buttonState = 0; 
int lastButtonState = HIGH;
long lastDebounceTime = 0;
long debounceDelay = 50;
int cycleState = 0;
int pressState = 0;


/*_______________________________void setup_____________________________*/
void setup() {
  pinMode(togglePin1, INPUT);
  pinMode(togglePin2, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(statusPin, OUTPUT);
  pinMode(gatePin,OUTPUT);
  digitalWrite(togglePin1, HIGH);
  digitalWrite(togglePin2, HIGH);
  digitalWrite(buttonPin, HIGH);
  digitalWrite(statusPin, LOW);
  digitalWrite(gatePin, LOW);
  
}

void loop() {

/*__________________________IF nothing mode___________________________
When the toggle switch is in the OFF position, Nothing mode is engaged. 
Nothing mode has a status LED that blinks.
*/
  
if (digitalRead(togglePin1) == HIGH && 
    digitalRead(togglePin2) == HIGH)
    {
      unsigned long statusMillis = millis();
      if(statusMillis - previousMillis > statusInterval)
      {
        if (ledState == LOW)
          ledState = HIGH;
        else
          ledState = LOW;
              
        previousMillis = statusMillis;
        digitalWrite(statusPin, ledState);
      }  
}
   
/*__________________________IF automatic mode_______________________
When the toggle switch points downwards, Automatic mode is engaged.
*/
 
if (digitalRead(togglePin1) == LOW && 
    digitalRead(togglePin2) == HIGH)
    {
      unsigned long statusMillis = millis();
      if(statusMillis - previousMillis > statusInterval)
        {
          if (ledState == LOW)
            ledState = HIGH;
          else
            ledState = LOW;
          previousMillis = statusMillis;
          digitalWrite(statusPin, ledState);
          digitalWrite(gatePin, ledState);
      }  
} 


/*__________________________IF trigger mode_________________________
When the toggle switch points downwards, Automatic mode is engaged.
*/

if (digitalRead(togglePin1) == HIGH && 
    digitalRead(togglePin2) == LOW)
         {
          unsigned long statusMillis = millis();
          buttonState = digitalRead(buttonPin);
          if (buttonState != lastButtonState)
           {
            if(pressState == 0)
              pressState = 1;
            else
              pressState = 0;
           }
          lastButtonState = buttonState;
         if(statusMillis - previousMillis > statusInterval && 
           pressState == 1)
           {
            cycleState = 1;
              if (ledState == LOW)
                ledState = HIGH;
              else
                ledState = LOW;
             previousMillis = statusMillis;
             digitalWrite(statusPin, ledState);
             digitalWrite(gatePin, ledState);
          }
        if(pressState == 0 && 
           cycleState == 1)
           {
            cycleState = 0;
            digitalWrite(statusPin, cycleState);
            digitalWrite(gatePin, cycleState);
          }
     }
}

In trigger mode, your flashing logic only occurs when pressState is one. similarly, turning the led off only occurs when cycleState is one. From the program's initial state, neither of those things will be true until you press the button. So, if the led is on when you flip to trigger mode, it stays on. I can't see how your second problem occurs unless you've already visited trigger mode and returned to nothing with cycleState being one, then gone back to trigger.

I have rewritten my code this time calling functions. I have re-thinked my design concept. I have one physical toggle switch that is an ON-OFF-ON. Then I have a physical momentary push-button which I want to use as a "toggle switch".

But I see where I am making my mistake only...I do not understand how to correct it....it is, as you pointed out twice wildBill, my pushbutton code. The cycling of the LED will only occur as long as I keep my push button depressed. However, I thought (clearly I am wrong) that if I assign the variable of "1" to pressState, then that variable is true until I press the button again. In other words, when I press the button, the state changed, because of that state change I assign a variable and that variable stays as is assigned until I push the button again, assigning a different variable.

So I suppose I don't know/understand how to use the Debounce code (just to ensure noise doesn't switch states) AND a toggle code which will soft convert my push button into a toggle switch. Any help with that? Should I rather use the stateChangeDetection example and work that into my project along with the Debounce code? Will that be more applicable? I'm asking since I clearly don't fully understand my current usage of code in terms of soft-converting my pushbutton to a toggle switch.

To my shame and humility I have also discovered that the push button I is an always ON button and not an always OFF button....however, this shouldn't make much of a different except that my HIGH signal will start off as a LOW signal (using internal pull-up resistor) and I need to change my lastButtonState to HIGH instead of LOW.

Herewith my new code (without my gatePin as needed by the project - left it out to first see about getting it all working then just add the gatePin):

/*_______________Declarations___________*/
const int LED = 13;                           //use build-in LED on pin 13
const int toggle1 = 3;                        //use pin 3 as an INPUT
const int toggle2 = 4;                        //use pin 4 as an INPUT
const int button = 7;                         //use pin 2 as an INPUT
int buttonState = 0;                          //variable to assign button changes
int pressState;                               //variable to assign button condition changes
int lastButtonState = LOW;                   //lastButtonState is set to LOW since pull-up resistor makes always-ON switch pull LOW
long lastDebounceTime = 0;                    //the last time the output pin was toggled
long debounceDelay = 20;                      //the debounce time; increase if the output flickers

/*_______________void setup_____________*/
void setup()
{
  pinMode (LED, OUTPUT);                      //set pin 13 an OUTPUT
  pinMode (toggle1, INPUT);                   //set pin 3 an INPUT
  pinMode (toggle2, INPUT);                   //set pin 4 an INPUT
  pinMode (button, INPUT);                    //set pin 5 an INPUT

  digitalWrite (toggle1, HIGH);               //enable internal pull-up resistor
  digitalWrite (toggle2, HIGH);               //enable internal pull-up resistor
  digitalWrite (button, HIGH);                //enable internal pull-up resistor
}

/*_______________function offMode_______*/
void offMode()
{
  pressState = false;                         //force button as not been pressed
  digitalWrite(LED, HIGH);                    //Switch on LED to indicated AC circuit is safe
}


/*_______________function autoMode_______*/
void autoMode()
{
  pressState = false;                         //force button as not been pressed
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
}


/*_______________function cycleMode_______*/
void cycleMode()
{

  digitalWrite(LED, HIGH);
  delay(500);
  digitalWrite(LED, LOW);
  delay(500);
}


/*_______________function triggerCheck_______*/
void triggerCheck()                                    //check for button presses using debounce
{
  int reading = digitalRead(button);                   //read the state of the button into a local variable
    if (reading != lastButtonState)                    //If the switched changed due to noise of pressing
      {
        lastDebounceTime = millis();                   // reset the debouncing timer
      } 
    if ((millis() - lastDebounceTime) > debounceDelay) //whatever teh reading is, it's been there for longer than 
      {                                                //the debounce delay, so take it as the actual current state
        buttonState = reading;
        if(pressState == false)                        //if pressState is false
         pressState = true;                            //set the pressState to opposite current state (start cycle)
        else                           
         pressState = false;                           //set the pressState to opposite current state (stop cycle) 
       }
    lastButtonState = buttonState;                     //save the reading so next time it'll be the lastButtonState

}


/*_______________void loop________________*/
void loop()
{

/*_______________OFF mode_________________*/  
  if (digitalRead(toggle1) == HIGH &&
      digitalRead(toggle2) == HIGH)                //check condition of pin 2 & 3
      {
         offMode();                                //call offMode function
         pressState = false;                       //force button as not been pressed
         buttonState = 0;                          //reset triggerCheck function variables
         lastButtonState = HIGH;                   //reset triggerCheck variables
      }

/*_______________AUTO mode_________________*/     
  if (digitalRead(toggle1) == LOW &&
      digitalRead(toggle2) == HIGH)                //check condition of pin 2 & 3
      {
        autoMode();                                //call autoMode function
        pressState = false;                        //force button as not been pressed
        buttonState = 0;                           //reset triggerCheck function variables
        lastButtonState = HIGH;                    //reset triggerCheck variables
      }

/*_______________TriggerReady mode____________*/      
  if(digitalRead(toggle1) == HIGH &&               //check for pin 3 HIGH signal
     digitalRead(toggle2) == LOW &&                //check for pin 4 LOW signal
     pressState == false)                          //the button has not been pressed yet as forced in AUTO & OFF mode
     {
       digitalWrite(LED, LOW);                     //make pin 13 LOW, trigger must start blink
       triggerCheck();                             //call triggerCheck function to check for button presses
     }
     
/*_______________TriggerPressed mode____________*/      
  if(digitalRead(toggle1) == HIGH &&               //check for pin 3 HIGH signal
     digitalRead(toggle2) == LOW &&                //check for pin 4 LOW signal
     pressState == true)                           //the button has been pressed as assigned in triggerCheck function
     {
       triggerCheck();                             //call triggerCheck function to check for button presses
       cycleMode();                                //call CYCLEmode to cycle 
     }
  
}

int lastButtonState = HIGH;                   //lastButtonState is set to HIGH since pull-up resistor makes always-ON switch pull LOW

/*_______________function triggerCheck_______*/
void triggerCheck()                                    //check for button presses using debounce
{
int reading = digitalRead(button);                   //read the state of the button into a local variable
if (reading != lastButtonState)                    //If the switched changed
  {
  if (reading==LOW) // Button is pressed 
    {                              
    delay(20);  //debounce
    pressState = !pressState;                       //flip pressState
    }
  }
lastButtonState = buttonState;                     //save the reading so next time it'll be the lastButtonState
}

/*_______________TriggerPressed mode____________*/
if(digitalRead(toggle1) == HIGH &&   digitalRead(toggle2) == LOW)  // Are we in trigger mode?
  {
  triggerCheck();                             // call triggerCheck function to check for button presses
  if(pressState)                                //Poor name, better would be cycleState   
    {
    cycleMode();                                //call CYCLEmode to cycle 
    }
  }

Hey wildBill. I haven't put that code of yours in my project, unfortunately I don't have the hardware handy at the moment. However I hope to review it tonight to see if I can understand it and then explain to you (if you do not mind) where I have done it wrong in my code. The code bugged me this whole weekend cause I really wanted to figure it out and get it right.

Thank you so much for the assistance!