Tscope5
Main Page
Related Pages
Files
Examples
keyboard01.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// keyboard01.c
// - Basic response timing example.
// - Use the keyboard for response registration.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
int
main()
{
// open a display
ts5_install_display
();
ts5_set_coordinate_scale
(TS5_RELATIVE_COORDINATES);
ts5_set_coordinate_system
(TS5_DISPLAY_COORDINATES);
ts5_set_text_alignment
(TS5_ALIGN_LEFT);
// define all keyboard buttons as responses
int
i, nbuttons =
ts5_get_num_keyboard_buttons
();
for
(i=0; i<nbuttons; i++) {
// buttons are counted from one
ts5_define_keyboard_button
(i+1);
}
// timing variables
double
start, stop, rt, error;
int
resp;
// instruction
ts5_clear_display
();
ts5_printf
(0.1, 0.1,
"press a keyboard button"
);
ts5_printf
(0.1, 0.2,
"within 5 seconds"
);
start =
ts5_flip_display
();
// flush the response buffer
ts5_flush_responses
();
// wait for a response
resp =
ts5_wait_for_response_timed
(&stop, &error, 5.0);
rt = stop-start;
// print response time and measurement error
// measurement error is only known
// for parallel port response boxes
// and cedrusboxes
ts5_printf
(0.1, 0.3,
"response %d"
, resp);
ts5_printf
(0.1, 0.4,
"start time %f"
, start);
ts5_printf
(0.1, 0.5,
"stop time %f"
, stop);
ts5_printf
(0.1, 0.6,
"response time %f"
, rt);
ts5_printf
(0.1, 0.7,
"measurement error %f"
, error);
ts5_flip_display
();
// wait for a click
ts5_draw_mouse_button
(0.8, 0.8);
return
0;
}