Measuring Reaction Time When A Box Changes Color

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:

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.
1 Like