Skip to main content
Skip table of contents

Recording digital input from a RESPONSEPixx

This demo prints how many digital IOs you have access to. Since it interacts with a RESPONSEPixx, it changes five IOs to outputs. Lines 30-32 show how this is done. The value 0x1F0000 means that digital IOs 16 to 20 are reprogrammed as digital outs. This comes from the binary representation of 0x1F0000, which is 0b0001 1111 0000 0000 0000 0000 (which represents IOs 0 to 23).

This demo also uses markers. Markers are used for measuring the time seperating two specific events. As a first step, you must do your first marker, Datapixx('SetMarker');, then you must decide when that marker should occur. In this example, let us use the video sync: Datapixx('RegWrRdVideoSync');. You cannot get a value of the device time on that marker: stimulusOnsetTime = Datapixx('GetMarker');.

After this, we set up our button box: Datapixx('EnableDinDebounce');, this allows us to ignore the values that oscillate when a button is pushed. Datapixx('SetDinLog'); tells the device that we are going to log all the RESPONSEPixx presses. Like a schedule, you must then start the logging operation Datapixx('StartDinLog');.

Once the experiement is started, you can get the reactions/buttons presses and their timestamps using [data tt] = Datapixx('ReadDinLog');. You can also get a response time with the difference between the timestamps and the marker.

MATLAB
function DatapixxDinBasicDemo()
% DatapixxDinBasicDemo()
%
% Demonstrates the basic functions of the DATAPixx TTL digital inputs.
% Prints the number of TTL inputs in the system,
% then logs button presses until user hits a key.
%
% Also see: DatapixxSimonGame
%
% History:
%
% Oct 1, 2009  paa     Written
% Oct 29, 2014 dml     Revised 

AssertOpenGL;   % We use PTB-3

% Open Datapixx, and stop any schedules which might already be running
Datapixx('Open');
Datapixx('StopAllSchedules');
Datapixx('RegWrRd');    % Synchronize DATAPixx registers to local register cache

% Show how many TTL input bits are in the Datapixx
nBits = Datapixx('GetDinNumBits');
fprintf('\nDATAPixx has %d TTL input bits\n', nBits);

% RESPONSEPixx has 5 illuminated buttons.
% We drive those button lights by turning around 5 DIN bits to outputs.
% Test paradigms could illuminate only the buttons which are valid in context.
% (eg: 1 button when waiting for subject to initiate a trial,
% 2 other buttons when waiting for 2-alternative forced-choice response).
Datapixx('SetDinDataDirection', hex2dec('1F0000'));
Datapixx('SetDinDataOut', hex2dec('1F0000'));
Datapixx('SetDinDataOutStrength', 1);   % Set brightness of buttons

% We'll say that we want to calculate response times
% from a stimulus appearing at the next vertical sync.
Datapixx('SetMarker');
Datapixx('RegWrRdVideoSync');
stimulusOnsetTime = Datapixx('GetMarker');

% Fire up the logger
Datapixx('EnableDinDebounce');      % Filter out button bounce
%Datapixx('DisableDinDebounce');    % Uncomment this line to log gruesome details of button bounce
Datapixx('SetDinLog');              % Configure logging with default values
Datapixx('StartDinLog');
Datapixx('RegWrRd');

% Show initial state of all the digital input bits
fprintf('Initial digital input states = ');
initialValues = Datapixx('GetDinValues');
for bit = nBits-1:-1:0               % Easier to understand if we show in binary
    if (bitand(initialValues, 2^bit) > 0)
        fprintf('1');
    else
        fprintf('0');
    end
end
fprintf('\n');

% Report logged button activity until keyboard is pressed
fprintf('\nPlug button box into Digital IN db-25\n');
fprintf('Press buttons to see new log entries\n');
fprintf('Hit any key to stop...\n');
if (exist('OCTAVE_VERSION'))
    fflush(stdout);
end
while ~KbCheck
    Datapixx('RegWrRd');
    status = Datapixx('GetDinStatus');
    if (status.newLogFrames > 0)
        [data tt] = Datapixx('ReadDinLog');
        for i = 1:status.newLogFrames
            fprintf('responseTime = %f', tt(i)-stimulusOnsetTime);
            fprintf(', button states = ');
            for bit = 15:-1:0               % Easier to understand if we show in binary
                if (bitand(data(i), 2^bit) > 0)
                    fprintf('1');
                else
                    fprintf('0');
                end
            end
            fprintf('\n');
        end
        if (exist('OCTAVE_VERSION'))
            fflush(stdout);
        end
    end
end

% Show final status of digital input logger
fprintf('\nStatus information for digital input logger:\n');
disp(Datapixx('GetDinStatus'));

% Job done
Datapixx('StopDinLog');
Datapixx('RegWrRd');
Datapixx('Close');
fprintf('\n\nDemo completed\n\n');
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.