The following code snippet fails to read the Gamepad ONLY for the first time through the
loop if I OMIT the initial call to Gamepad('GetNumButtons', 1); That is, if I just hard code
the number of buttons and make the first "contact" with Gamepad the call in which I set
buttons = [Gamepad('GetButton', 1, 1)... I get no reading of the gamepad the first time
through the loop, after that it is fine. If I include the prior call, as below, all works as
expected...
-m
numButtons = Gamepad('GetNumButtons', 1);
%for some reason Gamepad('GetButton...) does not work correctly unless you
%make a call to Gamepad prior to the first GetButton call
buttons = zeros(1, numButtons);
Screen('DrawTexture', w, fixation); % display the fixation
start_block_time = Screen('Flip', w);
start_block_time = start_block_time + trialtime - stimtime;
WaitSecs(trialtime - stimtime);
Screen('DrawTexture', w, fixationB);
%detect when the fixation turns blue
while (trial < trials)
vbl = Screen('Flip', w, start_block_time + (trialtime * trial) - slack);
while (GetSecs < (vbl + stimtime))
buttons=[Gamepad('GetButton', 1, 1) Gamepad('GetButton', 1, 2) Gamepad
('GetButton', 1, 3)];
checktime = GetSecs;
loop if I OMIT the initial call to Gamepad('GetNumButtons', 1); That is, if I just hard code
the number of buttons and make the first "contact" with Gamepad the call in which I set
buttons = [Gamepad('GetButton', 1, 1)... I get no reading of the gamepad the first time
through the loop, after that it is fine. If I include the prior call, as below, all works as
expected...
-m
numButtons = Gamepad('GetNumButtons', 1);
%for some reason Gamepad('GetButton...) does not work correctly unless you
%make a call to Gamepad prior to the first GetButton call
buttons = zeros(1, numButtons);
Screen('DrawTexture', w, fixation); % display the fixation
start_block_time = Screen('Flip', w);
start_block_time = start_block_time + trialtime - stimtime;
WaitSecs(trialtime - stimtime);
Screen('DrawTexture', w, fixationB);
%detect when the fixation turns blue
while (trial < trials)
vbl = Screen('Flip', w, start_block_time + (trialtime * trial) - slack);
while (GetSecs < (vbl + stimtime))
buttons=[Gamepad('GetButton', 1, 1) Gamepad('GetButton', 1, 2) Gamepad
('GetButton', 1, 3)];
checktime = GetSecs;