Error in reaction time tester

I am trying to make a device to test reaction tester. The device is supposed to turn on a randomly selected LED and start a timer and the user must press the corresponding button to stop the timer. The results of 5 tests are averaged for a total score.

The code compiles but after the start function runs the blue LED blinks and nothing else happens. I believe there is a problem with the test function but I am not sure.

//initialize LCD sreen
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

//initialize buzzer
const int buzzer = 13;

//initialize buttons and leds
//using analog pins for buttons because I dont have enough pins
const int blueLED = 6;
const int blueButton = A0;
const int redLED = 7;
const int redButton = A1;
const int greenLED = 8;
const int greenButton = A2;
const int yellowLED = 9;
const int yellowButton = A3;

//initialize timer
unsigned long startMillis;
unsigned long currentMillis;

//variables
long test_1;
long test_2;
long test_3;
long test_4;
long test_5;
long reaction_average;


void setup() {
  //set up LCD
  lcd.begin(16,2);
  lcd.setCursor(0,1);
  lcd.print("Ready reaction test!");
  
  //set up buzzer
  pinMode(buzzer, OUTPUT);
  //set up buttons and leds
  pinMode(blueLED, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);
  pinMode(redLED, OUTPUT);
  pinMode(redButton, INPUT_PULLUP);
  pinMode(greenLED, OUTPUT);
  pinMode(greenButton, INPUT_PULLUP);
  pinMode(yellowLED, OUTPUT);
  pinMode(yellowButton, INPUT_PULLUP);

}

void loop() {
Start();    //run start function

test_1 = Test();    //run test function 5 times and 
delay(1000);        //save results
test_2 = Test();
delay(1000);
test_3 = Test();
delay(1000);
test_4 = Test();
delay(1000);
test_5 = Test();
delay(1000);

reaction_average = ((test_1 + test_2 + test_3 + test_4 + test_5)/5);    //calculate average reaction time
lcd.setCursor(0,1);                                                     //and print results for user
lcd.clear();
lcd.print("Your average reaction time is");
lcd.setCursor(1, 1);
lcd.print(reaction_average);

}


void Start(){
  lcd.setCursor(0,1);         //plays welcome message on startup
  lcd.clear();
  lcd.print("Ready test in:");
  delay(2000);
  lcd.setCursor(0,1);
  lcd.clear();
  lcd.print("3");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.clear();
  lcd.print("2");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.clear();
  lcd.print("1");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.clear();
  lcd.print("GO!");
}


long Test(){
  int  rando = random(1, 5);    //save random number
  long reaction;                
  
  if(rando = 1){
    
    digitalWrite(blueLED, HIGH);    //turn on LED
    startMillis = millis();        //timer start time
    if(blueButton == HIGH){         //user presses button
      currentMillis = millis();     //timer stop time
      }
    digitalWrite(blueLED, LOW);  
    reaction = startMillis - currentMillis;   //calculates reaction time
    return reaction;    //return result in milliseconds
  }
  
  else if(rando = 2){
       
    digitalWrite(redLED, HIGH);
    startMillis = millis();  //timer start time
    if(redButton == HIGH){
      currentMillis = millis();
      }
    digitalWrite(redLED, LOW);  
    reaction = startMillis - currentMillis;
    return reaction;    //in milliseconds
  }
  
  else if(rando = 3){
       
    digitalWrite(greenLED, HIGH);
    startMillis = millis();  //timer start time
    if(greenButton == HIGH){
      currentMillis = millis();
      }
    digitalWrite(greenLED, LOW);  
    reaction = startMillis - currentMillis;
    return reaction;    //in milliseconds
  }
  
  else if(rando = 4){
       
    digitalWrite(greenLED, HIGH);
    startMillis = millis();  //timer start time
    if(greenButton == HIGH){
      currentMillis = millis();
      }
    digitalWrite(greenLED, LOW);  
    reaction = startMillis - currentMillis;
    return reaction;    //in milliseconds
  }
}

delay() stops regular code execution for the delay interval.
You can replace delay() with a technique called Blink Without Delay, BWD.
When using BWD, your sketch can run other code during the delay time.
Read Robin2’s discussion, Demonstration code for several things at the same time:
https://forum.arduino.cc/index.php?topic=223286.0

if(rando = 1){
Is not the same as:
if(rando == 1){

= is assignment == is comparison.

pinMode(blueButton, INPUT_PULLUP); // pin is now normally HIGH, and a button connected between pin and ground can pull the pin LOW when pressed.

if(blueButton == HIGH){ //user presses button ?

if(digitalRead(blueButton) == LOW) { // if user presses button

larryd:
delay() stops regular code execution for the delay interval.
You can replace delay() with a technique called Blink Without Delay, BWD.
When using BWD, your sketch can run other code during the delay time.
Read Robin2’s discussion, Demonstration code for several things at the same time:
https://forum.arduino.cc/index.php?topic=223286.0

if(rando = 1){
Is not the same as:
if(rando == 1){

= is assignment == is comparison.

Thanks for the correction on assignment and comparison. Does the delay function stop my LEDs from working properly with the button input? Im not trying to blink them so I didn't think the delays would matter.

delay() stops program execution for the delay amount of time.
Nothing can be scanned, read, printed or controlled.
If a LED is ‘on’ when delay() starts then it remains ‘on’ during the delay time.

Do you understand what Wawa is saying here?
if(blueButton == HIGH){
Is not the same as:
if(digitalRead(blueButton) == HIGH){

larryd:
delay() stops program execution for the delay amount of time.
Nothing can be scanned, read, printed or controlled.
If a LED is ‘on’ when delay() starts then it remains ‘on’ during the delay time.

Do you understand what Wawa is saying here?
if(blueButton == HIGH){
Is not the same as:
if(digitalRead(blueButton) == HIGH){

I shouldnt have any delays while LEDs are on because that would make my timer not function correctly for the reaction time calculation. The LEDs should only be turning on when their random function is called.

Wawa:
pinMode(blueButton, INPUT_PULLUP); // pin is now normally HIGH, and a button connected between pin and ground can pull the pin LOW when pressed.

if(blueButton == HIGH){ //user presses button ?

You seem to be saying that I had the button coded backwards so the if would always pass instantly and making the led only flash for an instant. I changed it and I would have thought that the LEDs would remain on until the button was pressed but it is still flashing on for an instant and seemingly passing the if statement instantly. What am I missing?

if(rando == 1){
    
    digitalWrite(blueLED, HIGH);    //turn on LED
    startMillis = millis();        //timer start time
    if(digitalRead(blueButton) == LOW){         //user presses button
      stopMillis = millis();     //timer stop time
      }
    digitalWrite(blueLED, LOW);  
    reaction = startMillis - stopMillis;   //calculates reaction time
    return reaction;    //return result in milliseconds
  }

Take is slow.

Do you understand how this works?

//Reaction time

const int blueLED = 6;
//const int blueLED = 13;
const int blueButton = A0;

byte          lastState;

unsigned long startMillis;
unsigned long currentMillis;

//***************************************************************
void setup()
{
  Serial.begin(9600);
  Serial.println("Ready reaction test!");

  pinMode(blueLED, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);

} //END of setup()

//***************************************************************
void loop()
{
  //if the LED is off, turn it on after a random delay
  if (digitalRead(blueLED) == LOW)
  {
    //one time you can use delay()   <----<<<<   ;-)
    delay(random(2000, 5000));     
    
    //timer start time
    startMillis = millis();        
    
    //turn on LED
    digitalWrite(blueLED, HIGH);   
  }

  checkSwitches();

} //END of  loop()

//***************************************************************
void checkSwitches()
{
  byte currentState = digitalRead(blueButton);

  //has the switch changed state?
  if (currentState != lastState)
  {
    //update to the new state
    lastState = currentState;

    //is the switch pressed now?
    if (currentState == LOW)
    {
      Serial.print("Your reaction time in milliseconds is = ");
      Serial.println((millis() - startMillis));
      
      //turn off the LED
      digitalWrite(blueLED, LOW);
    }
  }

} //END of checkSwitch()

larryd:
Take is slow.

Do you understand how this works?

//Reaction time

const int blueLED = 6;
//const int blueLED = 13;
const int blueButton = A0;

byte          lastState;

unsigned long startMillis;
unsigned long currentMillis;

//***************************************************************
void setup()
{
  Serial.begin(9600);
  Serial.println("Ready reaction test!");

pinMode(blueLED, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);

} //END of setup()

//***************************************************************
void loop()
{
  //if the LED is off, turn it on after a random delay
  if (digitalRead(blueLED) == LOW)
  {
    //one time you can use delay()  <----<<<<  :wink:
    delay(random(2000, 5000));   
   
    //timer start time
    startMillis = millis();       
   
    //turn on LED
    digitalWrite(blueLED, HIGH); 
  }

checkSwitches();

} //END of  loop()

//***************************************************************
void checkSwitches()
{
  byte currentState = digitalRead(blueButton);

//has the switch changed state?
  if (currentState != lastState)
  {
    //update to the new state
    lastState = currentState;

//is the switch pressed now?
    if (currentState == LOW)
    {
      Serial.print("Your reaction time in milliseconds is = ");
      Serial.println((millis() - startMillis));
     
      //turn off the LED
      digitalWrite(blueLED, LOW);
    }
  }

} //END of checkSwitch()

I thought I understood your code and I tried to implement it. My LEDs now come on and stay on after their random function is run until all 4 come on and stay on until i reset the board. I think the main reason my code isnt working at this point is because your reflex tester uses the loop to check parts and mine cant because I want to get an average of 5. I really appreciate the help.

The offered code should work with your system as is.

When you open your Serial monitor (which is set to 9600 baud), you should see:

Ready reaction test!

After 2 seconds but before 5 seconds the Blue LED should come on.

When you see the LED turn ON, you operate the switch, the reaction time will be printed to your Serial monitor.

Things then repeat.

Adding averaging etc. is a simple matter of getting the code written, but this sample code should get you started.

Are you seeing the above mentioned sequence occur?

"I thought I understood your code and I tried to implement it."

Then show us your changes.

BTW

Why are you doing this?

larryd:
The offered code should work with your system as is.

When you open your Serial monitor (which is set to 9600 baud), you should see:

Ready reaction test!

After 2 seconds but before 5 seconds the Blue LED should come on.

When you see the LED turn ON, you operate the switch, the reaction time will be printed to your Serial monitor.

Things then repeat.

Adding averaging etc. is a simple matter of getting the code written, but this sample code should get you started.

Are you seeing the above mentioned sequence occur?

"I thought I understood your code and I tried to implement it."

Then show us your changes.

BTW

Why are you doing this?

I meant to paste my new code with that.

I ran your code with my exact setup and it worked perfectly as you described. I have been coding for a bit but I dont know arduino very well. I am doing this as a project to try to practice.

//initialize LCD sreen
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//initialize buzzer
const int buzzer = 13;

//initialize buttons and leds
//using analog pins for buttons because I dont have enough pins
const int blueLED = 6;
const int blueButton = A0;
const int redLED = 7;
const int redButton = A1;
const int greenLED = 8;
const int greenButton = A2;
const int yellowLED = 9;
const int yellowButton = A3;

int ledState = LOW;
unsigned long previousMillis = 0;


//initialize timer
unsigned long startMillis;
unsigned long stopMillis;

byte lastButtonState;

//variables
long test_1;
long test_2;
long test_3;
long test_4;
long test_5;
long reaction_total;
long reaction_average;


void setup() {
  //set up LCD
  lcd.begin(16, 2);
  lcd.setCursor(0, 1);
  lcd.print("Ready reaction test!");

  //set up buzzer
  pinMode(buzzer, OUTPUT);
  //set up buttons and leds
  pinMode(blueLED, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);
  pinMode(redLED, OUTPUT);
  pinMode(redButton, INPUT_PULLUP);
  pinMode(greenLED, OUTPUT);
  pinMode(greenButton, INPUT_PULLUP);
  pinMode(yellowLED, OUTPUT);
  pinMode(yellowButton, INPUT_PULLUP);

}

void loop() {
  Start();    //run start function

  test_1 = Test();    //run test function 5 times and
  delay(1000);        //save results
  test_2 = Test();
  delay(1000);
  test_3 = Test();
  delay(1000);
  test_4 = Test();
  delay(1000);
  test_5 = Test();
  delay(1000);

  reaction_total = (test_1 + test_2 + test_3 + test_4 + test_5);          //calculate average reaction time
  reaction_average = (reaction_total / 5);
  lcd.setCursor(0, 1);                                                    //and print results for user
  lcd.clear();
  lcd.print("Average Reaction:");
  lcd.setCursor(1, 1);
  lcd.print(reaction_average);
  delay(5000);

}


void Start() {
  lcd.setCursor(0, 1);        //plays welcome message on startup
  lcd.clear();
  lcd.print("Ready test in:");
  delay(2000);
  lcd.setCursor(0, 1);
  lcd.clear();
  lcd.print("3");
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.clear();
  lcd.print("2");
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.clear();
  lcd.print("1");
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.clear();
  lcd.print("GO!");
}


long Test() {
  int  rando = random(1, 5);    //save random number
  long reaction;

  if (rando == 1) {

    if (digitalRead(blueLED) == LOW) {
      startMillis = millis();
      digitalWrite(blueLED, HIGH);
    }

    byte currentButtonState = digitalRead(blueButton);

    if (currentButtonState != lastButtonState) {
      lastButtonState = currentButtonState;
      if (currentButtonState == LOW) {
        stopMillis = millis();
        digitalWrite(blueLED, LOW);
        
      }
    }
    reaction = startMillis - stopMillis;
    return reaction;

  }

  else if (rando == 2) {

    if (digitalRead(redLED) == LOW) {
      startMillis = millis();
      digitalWrite(redLED, HIGH);
    }

    byte currentButtonState = digitalRead(redButton);

    if (currentButtonState != lastButtonState) {
      lastButtonState = currentButtonState;
      if (currentButtonState == LOW) {
        stopMillis = millis();     
        digitalWrite(redLED, LOW);
      }
    }
    reaction = startMillis - stopMillis;
    return reaction;

    
  }

  else if (rando == 3) {

    if (digitalRead(greenLED) == LOW) {
      startMillis = millis();
      digitalWrite(greenLED, HIGH);
    }

    byte currentButtonState = digitalRead(greenButton);

    if (currentButtonState != lastButtonState) {
      lastButtonState = currentButtonState;
      if (currentButtonState == LOW) {
        stopMillis = millis();
        digitalWrite(greenLED, LOW);
      }
    }
    reaction = startMillis - stopMillis;
    return reaction;
    
  }

  else if (rando == 4) {

    if (digitalRead(yellowLED) == LOW) {
      startMillis = millis();
      digitalWrite(yellowLED, HIGH);
    }

    byte currentButtonState = digitalRead(yellowButton);

    if (currentButtonState != lastButtonState) {
      lastButtonState = currentButtonState;

      if (currentButtonState == LOW) {
        stopMillis = millis();
        digitalWrite(yellowLED, LOW);
      }
    }
    reaction = startMillis - stopMillis;
    return reaction;
    
  }
}

Do you know what a 'State Machine' is?

larryd:
Do you know what a 'State Machine' is?

I don't think Ive ever heard of it before. it looks like it does something dependent on the state of some sort of input. The practical application seems to use case statements.

This should be close, do you understand what is happening?

You should be able to add the remainder of your switches and LEDs to the sketch.

//Version 1.01

//No effort has been made to reduce the sketch size
//initialize LCD screen
#include<LiquidCrystal.h>

#define LEDon  HIGH
#define LEDoff !LEDon

//     LCD pins:  RS  EN DB4 DB5 DB6 DB7
//LiquidCrystal lcd( 9,  8, 30,  7,  6, 5);
//const byte backLight   = 17;
//const int blueLED      = 13;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int blueLED      = 6;

const int blueButton   = A0;

unsigned long startMillis;

//the time it took to operate the switch
unsigned long testTime;

//storage for our 5 read values 0-4
unsigned long testValue[5];
unsigned long reaction_average;

//0, 1, 2 and 3 are valid states for our 'State Machine'
byte mState;

//the test we are now running 0-4
byte counter;

//this is the switch we are currently testing
byte testingSwitch;
//the current state the switch is in
byte currentState;
//the last state the blue switch was in
byte lastBlueState;

//byte variables for our other 'last' switch states goes here  <-----<<<<<

//when 'testFlag' is true, we are currently testing the user
bool testFlag = false;

//*********************************************************************
void setup()
{
  //set up LCD
  lcd.begin(16, 2);
  lcd.setCursor(0, 1);
  lcd.print("Ready reaction test!");

  //pinMode(backLight, OUTPUT);
  //turn on backlight
  //digitalWrite(backLight, HIGH);

  pinMode(blueLED, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);
  lastBlueState = digitalRead(blueButton);

} //END of setup()

//*********************************************************************
void loop()
{
  //State Machine
  switch (mState)
  {
    //****************
    case 0:
      lcd.setCursor(0, 1);        //plays welcome message on startup
      lcd.clear();
      lcd.print("New test in:");
      delay(2000);
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("3");
      delay(1000);
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("2");
      delay(1000);
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("1");
      delay(1000);

      counter = 0;

      mState = 1;

      break;

    //****************
    case 1:
      //are we currently testing?
      if (testFlag == false)
      {
        if (counter < 5)
        {
          lcd.clear();
          lcd.print("Test = ");
          lcd.print(counter + 1);

          //proceed with testing
          //Note: 'testFlag' is controlled within this function
          runTest();

          //check for user reaction
          mState = 2;
        }

        else
        {
          //get ready for the next test
          counter = 0;

          //we have our 5 tests, print the results
          mState = 3;
        }

      }

      break;

    //****************
    case 2:
      //'testFlag' will be set false when our switch goes LOW
      if (testFlag == false)
      {
        //store this value
        testValue[counter] = testTime;

        counter++;

        //back to start the next test
        mState = 1;
      }

      else
      {
        //check our switch
        //Note: 'testFlag' is controlled within this function
        runTest();
      }

      break;

    //****************
    case 3:
      unsigned long average = 0;

      for (byte x = 0; x <= 4; x++)
      {
        average += testValue[x];
      }

      reaction_average = average / 5;
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("Average Reaction:");
      lcd.setCursor(1, 1);
      lcd.print(reaction_average);

      delay(5000);

      mState = 0;

      break;

      //****************

  } //END of   switch/case

} //END of loop()

//*********************************************************************
void runTest()
{
  //**********************************************
  //are we currently testing?
  if (testFlag == false)
  {
    //some random amount of time to wait
    delay(random(1000, 4000));

    //  int  rando = random(1, 5);  //                   <-----<<<<  uncomment, add other switch stuff
    int  rando = 1;                       //for testing  <-----<<<<  comment out

    //**************************
    if (rando == 1)
    {
      testingSwitch = blueButton;

      //turn on LED
      digitalWrite(blueLED, LEDon);
      //start the timer
      startMillis = millis();
    }

    //**************************
    //Other switches will go here
    //**************************

    //we are now testing
    testFlag = true;

  } //END of     if (testFlag == false)


  //**********************************************
  //are we currently testing?
  if (testFlag == true)
  {
    //**********************
    //blue button
    if (testingSwitch == blueButton)
    {
      currentState = digitalRead(blueButton);

      if (lastBlueState != currentState)
      {
        //update to the new state
        lastBlueState = currentState;

        if (currentState == LOW)
        {
          //turn off LED
          digitalWrite(blueLED, LEDoff);

          //we are finished testing
          testFlag = false;

          testTime = millis() - startMillis;
        }

      }

    } //END of   if (testingSwitch == blueButton)

    //**********************
    //Other switches will go here
    //**********************

  } //END of   if (testFlag == true)

} //END of    runTest()

Edit
Added comments, now at:
Version 1.01

larryd:
This should be close, do you understand what is happening?

You should be able to add the remainder of your switches and LEDs to the sketch.

//Version 1.01

//No effort has been made to reduce the sketch size
//initialize LCD screen
#include<LiquidCrystal.h>

#define LEDon  HIGH
#define LEDoff !LEDon

//    LCD pins:  RS  EN DB4 DB5 DB6 DB7
//LiquidCrystal lcd( 9,  8, 30,  7,  6, 5);
//const byte backLight  = 17;
//const int blueLED      = 13;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int blueLED      = 6;

const int blueButton  = A0;

unsigned long startMillis;

//the time it took to operate the switch
unsigned long testTime;

//storage for our 5 read values 0-4
unsigned long testValue[5];
unsigned long reaction_average;

//0, 1, 2 and 3 are valid states for our 'State Machine'
byte mState;

//the test we are now running 0-4
byte counter;

//this is the switch we are currently testing
byte testingSwitch;
//the current state the switch is in
byte currentState;
//the last state the blue switch was in
byte lastBlueState;

//byte variables for our other 'last' switch states goes here  <-----<<<<<

//when 'testFlag' is true, we are currently testing the user
bool testFlag = false;

//*********************************************************************
void setup()
{
  //set up LCD
  lcd.begin(16, 2);
  lcd.setCursor(0, 1);
  lcd.print("Ready reaction test!");

//pinMode(backLight, OUTPUT);
  //turn on backlight
  //digitalWrite(backLight, HIGH);

pinMode(blueLED, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);
  lastBlueState = digitalRead(blueButton);

} //END of setup()

//*********************************************************************
void loop()
{
  //State Machine
  switch (mState)
  {
    //****************
    case 0:
      lcd.setCursor(0, 1);        //plays welcome message on startup
      lcd.clear();
      lcd.print("New test in:");
      delay(2000);
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("3");
      delay(1000);
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("2");
      delay(1000);
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("1");
      delay(1000);

counter = 0;

mState = 1;

break;

//****************
    case 1:
      //are we currently testing?
      if (testFlag == false)
      {
        if (counter < 5)
        {
          lcd.clear();
          lcd.print("Test = ");
          lcd.print(counter + 1);

//proceed with testing
          //Note: 'testFlag' is controlled within this function
          runTest();

//check for user reaction
          mState = 2;
        }

else
        {
          //get ready for the next test
          counter = 0;

//we have our 5 tests, print the results
          mState = 3;
        }

}

break;

//****************
    case 2:
      //'testFlag' will be set false when our switch goes LOW
      if (testFlag == false)
      {
        //store this value
        testValue[counter] = testTime;

counter++;

//back to start the next test
        mState = 1;
      }

else
      {
        //check our switch
        //Note: 'testFlag' is controlled within this function
        runTest();
      }

break;

//****************
    case 3:
      unsigned long average = 0;

for (byte x = 0; x <= 4; x++)
      {
        average += testValue[x];
      }

reaction_average = average / 5;
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("Average Reaction:");
      lcd.setCursor(1, 1);
      lcd.print(reaction_average);

delay(5000);

mState = 0;

break;

//****************

} //END of  switch/case

} //END of loop()

//*********************************************************************
void runTest()
{
  //**********************************************
  //are we currently testing?
  if (testFlag == false)
  {
    //some random amount of time to wait
    delay(random(1000, 4000));

//  int  rando = random(1, 5);  //                  <-----<<<<  uncomment, add other switch stuff
    int  rando = 1;                      //for testing  <-----<<<<  comment out

//**************************
    if (rando == 1)
    {
      testingSwitch = blueButton;

//turn on LED
      digitalWrite(blueLED, LEDon);
      //start the timer
      startMillis = millis();
    }

//**************************
    //Other switches will go here
    //**************************

//we are now testing
    testFlag = true;

} //END of    if (testFlag == false)

//**********************************************
  //are we currently testing?
  if (testFlag == true)
  {
    //**********************
    //blue button
    if (testingSwitch == blueButton)
    {
      currentState = digitalRead(blueButton);

if (lastBlueState != currentState)
      {
        //update to the new state
        lastBlueState = currentState;

if (currentState == LOW)
        {
          //turn off LED
          digitalWrite(blueLED, LEDoff);

//we are finished testing
          testFlag = false;

testTime = millis() - startMillis;
        }

}

} //END of  if (testingSwitch == blueButton)

//**********************
    //Other switches will go here
    //**********************

} //END of  if (testFlag == true)

} //END of    runTest()





Edit 
Added comments, now at:
Version 1.01

I did a bit more reading about state machines today. It seems like a good way to allow exactly what I am trying to do. It reads a series of inputs and gives a different state with a switch depending on where you are within the steps. I can use this concept to move between the different stages of my code and ultimately end up with an average reaction time.

I see you made a sketch of exactly how I should use the state machine. I will implement it in my code and post the code once I am confident that I have used and understood it fully.

Thank you for all this help. I am learning a lot faster than I would without help and I truly appreciate it.