Tscope5
timer5.c

changing the stimulus while waiting for a response

#include <tscope5.h>
int main()
{
ts5_wait(2.0);
double start, stop, rt, error;
int i;
for (i=0; i<5; i++) {
ts5_printf(0.0, 0.0, "+");
unsigned int stim = ts5_random_integer(2);
if (stim==0) {
stim='S';
}
else {
stim='L';
}
// put on the stimulus
ts5_printf(0.0, 0.0, "%c", stim);
ts5_wait(0.5);
start = ts5_flip_display();
// clear the display after 0.5 seconds
ts5_wait(0.5);
// wait until 2 seconds after the stimulus
int resp = ts5_wait_for_response_until(&stop, &error, start + 2.0);
rt = stop-start;
ts5_printf(0.0, 20.0, "response %d", resp);
ts5_printf(0.0, 0.0, "rt %f", rt);
ts5_printf(0.0, -20.0, "measurement error %f", error);
ts5_wait(2.0);
}
return 0;
}