Experiments example 5: Response buttons experiment
The MEG Lab has two response boxes, which allow the participant to provide input during an experiment.
On the right box, the colors of the buttons from left to right are:
white
red
yellow
green
blue
On the left box, the order is the same, but from right to left.
The scripts can be found under experiments/psychtoolbox/general/; the main function is experiments/psychtoolbox/general/getButtonColor.m.
Warning
Both response boxes (left and right) need to be connected for the function to work correctly.
To test the response boxes, you can run the following script:
Datapixx('Open');
Datapixx('DisablePixelMode');
Datapixx('RegWr');
sel = struct();
sel.right_box = {'blue'};
sel.left_box = {'white','red'};
while true
% Block until any mapped button is pressed:
pair = getButtonColor(sel)
disp(['button pressed', pair]);
WaitSecs(0.5)
end
% % Non-blocking poll:
% pair = getbuttonColor([], false);
% if isempty(pair), disp('nothing yet'); end
%
% % Listen only to a subset:
% sel = struct();
% sel.('right box') = {'blue'};
% sel.('left box') = {'white','red'};
% pair = getbuttonColor(sel);
The getButtonColor() function:
takes as input a struct selecting the buttons to listen to
returns the response box that was pressed and the color of the pressed button
works either in blocking mode (it waits until a press is obtained) or in non-blocking mode (it listens for a button press for a single frame)