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

    timer5.c
    changing (erasing) the stimulus while waiting for a response
*/

#include <tscope.h>

#define FIXTM   mtt(500)
#define BLANKTM mtt(500)
#define STIMTM  50              // 50 syncs = 800ms @ 60Hz
#define MAXTM   mtt(700)


struct {
    int rt, err;
    int resp;
} data;

struct {
    __int64 junk;
    __int64 t1, e1;
    __int64 t2, e2;
    __int64 t3, e3;
} tmp;

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 - timing mark 1
    ts_vsync(&tmp.t1, &tmp.e1);
    ts_printf_centre(0, 0, "stimulus");

    // wait until response or maximum stimulus time
    data.resp = ts_vsyncresp(&tmp.t2, &tmp.e2, STIMTM);

    // clear the screen 
    ts_clrscr();

    // if no response yet, go on 
    // maximum time will be MAXTN + STIMTM
    if (!data.resp)
        data.resp = ts_resp(&tmp.t2, &tmp.e2, MAXTM);

    // compute rt
    data.rt = ttm(tmp.t2 - tmp.t1);
    data.err = 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();

    // define response key
    ts_defkey(M1);
    ts_defkey(M2);

    // execute trial
    trial();

    // print some results
    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.err);
    ts_mousepos(0, 0);

    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