Dear all,
My name is CHI. We designed a DIY device to measure left and right button pressing time. For example, the time of 1st left button pressing time is 1.556s, then the 2nd left button pressing maybe 3.778, after that the 1st right button pressing time is 5.557. The preference data example and our DIY device picture have been uploaded as attachments.
More importantly, we found one of the program from internet. But this one is not real what we want. This one may be suitable for measuring reaction time, which measure time interval between light open and pressing time.But we just want the pressing time.
Hence, any one can kindly help us to edit the program? Please help us. Many thanks.
volatile int state = 0;
int ledArray[] = {8, 9, 10, 11, 12};
int count = 0;
int timer = 1200;
int stopLed = 6;
int goLed = 7;
int randMin = 250;
int randMax = 750;
int startDelay = 750;
volatile float time ;
float start_time;
void setup() {
for (count=0;count< 5;count **){
pinMode(ledArray[count], OUTPUT);
}
attachInterrupt (0, ledonoff, RISING)
pinMode(stopLed, OUTPUT);
randomSeed(analogRead {0});
Serial.begin(9600);
}
void loop(){
//start state
if (state == 0) {
digitalWrite(stopLed, HIGH);
digitalWrite(goLed, LOW);
for (count=0;count< 5;count **){
digitalWrite(ledArray[count], LOW);
}
}
// start button pressed
if (state ==1){
// random start
startDelay = random(randMin,randMax);
delay(startDelay);
start_time = millis();
digitalWrite(stopLed, LOW)
digitalWrite(goLed, HIGH)
for (count=0;count< 5;count **){
delay(timer);
if (state ==2) {
time = (time - start_time)/1000;
Serial.print("Reaction time: " );
Serial.print(time);
Serial.println("seconds");
delay(1000);
break;
}
digitalWrite{ledArray[count], HIGH};
}
}
}
void Random()
{
randomTime = random(4,10);
randomTime = randomTime1000;
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(randomTime);
Start();
}
void Start(){
startTime = millis();
digitalWrite(ledPin, HIGH);
}
void Stop(){
endTime = millis();
elapsedTime = (endTime - startTime)+5;
elapsedTime = elapsedTime/1000;
Serial.print("Time Seconds: ");
Serial.println(elapsedTime);
digitalWrite(ledPin, LOW);
}void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

