Experiments example 5: Response buttons experiment

The MEG Lab has two response boxes which allow the user to provide their input during an experiment.

For the right box the colors of the buttons from left side to right side are: - white - red - yellow - green - blue

For the left box it is the same order above, but from right side to left side.

Scripts can be found under

experiments/psychtoolbox/general

experiments/psychtoolbox/general/getButtonColor.m

Warning

Both response boxes (left and right) need to be connected in order to have 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 selection of the buttons to listen to

    • provides as output the pressed button box and which button color

    • it can work in blocking (wait until a press is obtained) or non-blocking mode (a one frame pass on listening to the button press)