/*
          __
         / /_______________  ____  ___
        / __/ ___/ ___/ __ \/ __ \/ _ \
       / /_(__  ) /__/ /_/ / /_/ /  __/
       \__/____/\___/\____/ .___/\___/
                         /_/

    timer2.c
    basic timing with maximim response time 
*/

#include <tscope.h>

// timing constants
#define FIXTM   mtt(500)
#define BLANKTM mtt(500)
#define MAXTM   mtt(1500)

// structure for the data we're interested in
struct {
    int rt;
    int re;
    int resp;
} data;

// structure for temporary data
struct {
    __int64 junk;
    __int64 t1, e1;
    __int64 t2, e2;
} tmp;

// one trial sequence
void trial()
{
    // fixation
    ts_vsync(&tmp.junk, &tmp.junk);
    ts_printf_centre(0, 0, "+");
    ts_wait(FIXTM);

    // blank screen
    ts_vsync(&tmp.junk, &tmp.junk);
    ts_clrscr();
    ts_wait(BLANKTM);

    // stimulus
    ts_vsync(&tmp.t1, &tmp.e1);
    ts_printf_centre(0, 0, "stimulus");

    // response
    data.resp = ts_resp(&tmp.t2, &tmp.e2, MAXTM);
    ts_clrscr();

    // reaction time
    data.rt = ttm(tmp.t2 - tmp.t1);
    data.re = ttmu(tmp.e1 + tmp.e2);
}

int main()
{
    // prepare the subject
    ts_printf_centre(0, 20, "press one of the mouse buttons");
    ts_printf_centre(0, 0, "within 1500ms after the appearance");
    ts_printf_centre(0, -20, "of the stimulus");
    ts_button(XMAX - 20, -YMAX + 20);
    ts_clrscr();

    // set response values
    ts_defkey(M1);
    ts_defkey(M2);

    // execute trial
    trial();

    // print some results on the screen
    ts_printf_centre(0, 50, "response: %d", data.resp);
    ts_printf_centre(0, 0, "reaction time: %4d milliseconds", data.rt);
    ts_printf_centre(0, -50, "timing error: %4d microseconds", data.re);

    ts_button(XMAX - 20, -YMAX + 20);
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information