- A C library for programming cognitive experiments on Windows
/* __ / /_______________ ____ ___ / __/ ___/ ___/ __ \/ __ \/ _ \ / /_(__ ) /__/ /_/ / /_/ / __/ \__/____/\___/\____/ .___/\___/ /_/ timer1.c basic timing of stimulus onset and response */ #include <tscope.h> // trial timing constants // Tscope uses clock tics // use mtt function to convert milliseconds to tics #define FIXTM mtt(500) #define BLANKTM mtt(500) #define MAXTM mtt(0) // structure for the data we're interested in struct { int rt; // response time int re; // timing error int resp; // response value } data; // structure for temporary timing data // use 64 bit integers to store tic values struct { __int64 junk; // junk variabele __int64 t1, e1; // timestamp and error stimulus onset __int64 t2, e2; // timestamp and error response onset } tmp; int main() { // prepare the subject ts_printf_centre(0, 10, "press one of the mouse buttons"); ts_printf_centre(0, -10, "when the stimulus appears"); ts_button(XMAX - 20, -YMAX + 20); ts_clrscr(); // define response buttons (left and right mouse key) ts_defkey(M1); // the first defined key will have response ts_defkey(M2); // value 1, the second 2, etc. // fixation mark // we dont't use this timing mark for computation of // the reaction time -> put it in a junk variable ts_vsync(&tmp.junk, &tmp.junk); ts_printf_centre(0, 0, "+"); ts_wait(FIXTM); // blank screen // we don't use this timing mark either ts_vsync(&tmp.junk, &tmp.junk); ts_clrscr(); ts_wait(BLANKTM); // onset stimulus: this timing mark is the start of the rt ts_vsync(&tmp.t1, &tmp.e1); ts_printf_centre(0, 0, "stimulus"); // wait for a response (maximum time 0 = wait forever) data.resp = ts_resp(&tmp.t2, &tmp.e2, MAXTM); ts_clrscr(); // compute reaction time data.rt = ttm(tmp.t2 - tmp.t1); // reaction time=mark2-mark1, converted to ms data.re = ttmu(tmp.e1 + tmp.e2); // error=error1+error2, converted to us // print some results on the screen ts_printf_centre(0, 0, "response: %d.", data.resp); ts_printf_centre(0, -20, "reaction time: %d milliseconds.", data.rt); ts_printf_centre(0, -40, "timing error: %d microseconds.", data.re); ts_button(-XMAX + 20, YMAX - 20); return 0; } END_OF_MAIN();