Recording button activity from a RESPONSEPixx and I/O Hub
The TRACKPixx /mini kit includes an I/O Hub and 5-button RESPONSEPixx response box. This demo shows how to record button activity from the response box.
The I/O hub is treated like a joystick or gamepad by your operating system. This demo creates a joystick object using the Matlab-Input toolbox (formerly the HebiJoystick toolbox), and reads button activity.
A fullscreen window is opened and a circle is presented in the middle of the display. Pressing a button changes the colour of the circle to match the button. Pressing any key on the keyboard exits the program.
Button activity is printed to the screen, and saved in a cell array called 'data' along with reaction time (time since last Flip).
Citation:
Florian Enner (2023). HebiRobotics/HebiJoystick (https://github.com/HebiRobotics/MatlabInput), GitHub. Retrieved November 27, 2023.
% Initialize Psychtoolbox
PsychDefaultSetup(2);
Screen('Preference','SkipSyncTests',1);
% Initialize button box - assumes the 5-button RESPONSEPixx handheld.
% Change labels for different button box types.
joy = HebiJoystick(1);
buttonNames = {'Red', 'Yellow', 'Blue', 'Green', 'White'};
buttonColors = {[1,0,0],[1,1,0],[0,0,1],[0,1,0],[1,1,1]};
%Initialize response data
data = [];
buttonDown= 0;
% Open a fullscreen window
screenNumber = max(Screen('Screens'));
[win, rect] = PsychImaging('OpenWindow', screenNumber, 0); % 0 sets background color to black
% Set up circle parameters
circleRadius = 100;
circleColor = [1, 1, 1]; % Initial color (white)
circlePosition = [rect(3), rect(4)]/2;
% Display loop
while true
% Draw the circle
Screen('FillOval', win, circleColor, [circlePosition(1)-circleRadius, circlePosition(2)-circleRadius, circlePosition(1)+circleRadius, circlePosition(2)+circleRadius]);
[~, ~, t1, ~,~] = Screen('Flip', win);
% Check for button press
while true
[axes, buttons, povs] = read(joy);
buttons = buttons(1:numel(buttonNames));
%check for new press
if any(buttons) && ~buttonDown
t2 = GetSecs();
buttonID = buttonNames{find(buttons)};
circleColor = buttonColors{find(buttons)};
data = [data; {'Press', buttonID, t2-t1}];
buttonDown = 1;
fprintf('\nButton pressed! Button ID: %s', buttonID);
break
%check for release to reset buttonDown
elseif ~any(buttons) && buttonDown
buttonDown = 0;
t2 = GetSecs();
fprintf('\nButton released! Button ID: %s', buttonID);
data = [data; {'Release', buttonID, t2-t1}];
end
end
pause(0.01) %Adjust for CPU usage vs. sampling rate
%Check for escape
[keypress, ~,~] = KbCheck();
if keypress
break;
end
end
% Close the window
sca;