# Measuring Reaction Time When A Box Changes Color

**URL:** <https://discourse.processing.org/t/measuring-reaction-time-when-a-box-changes-color/29298>\
**Category:** Coding Questions\
**Created:** [April 12, 2021, 9:51am UTC](https://discourse.processing.org/t/measuring-reaction-time-when-a-box-changes-color/29298 "2021-04-12T09:51:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lestacos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lestacos/32/12787_2.png) [@lestacos](https://discourse.processing.org/u/lestacos)\
**Post date:** [April 12, 2021, 9:51am UTC](https://discourse.processing.org/t/measuring-reaction-time-when-a-box-changes-color/29298/1 "2021-04-12T09:51:52Z")

</div>

We are tasked with creating a Processing program which measures reaction time of a person.

The program should be able to:

- The user can start the experiment by pressing the SPACE key.
- At a random time (between 2 and 6 seconds) the color of a field will change (e.g., black to red) – this is the stimulus.
- When the field changed to red, the program waits for the user to press the SPACE key and measures the time needed.
- The measured time is stored in an array and displayed on the screen.
- By pressing the key ‘a’ the experiment is ended and the results (e.g., average time and the standard deviation) are shown.
- By pressing the SPACE key again, a new experiment is started.

So far we have created:

````auto
int maxTime = 6;
int minTime = 2; 

void setup() {
  size(500,500);
  background(0);
}

//void draw() {
   
//}

void keyPressed(){
  if(key== ' '){
    startingTime=millis();
    int seconds = startingTime/1000;
    int time =int(random(2,6));
    while(//seconds is within the limit of time){
      background(255,0,0);
    } 
     }
   
   //start  
  else if(key=='a'){ 
    fill(0);
    print(startingTime);
  }  

}```

Are we going about this in the right way? 

Thank you.
````
