digital_sample

下列程序另存为m文件

function digital_sample()

for (i = 1:20);
start = cputime;
time = (i-1)*0.050;
volts = edigitalin(-1,0,0,0);        % Sample analog signal using IO1
data(i,:) = [time volts];           % Data array for plotting
elapsed = cputime-start;            % Calculate the time elapsed during funciton call
pause(0.050-elapsed);               % Pause for remainder of 50 ms sample period 
end

% Plot data
plot(data(:,1),data(:,2));
title('Digital Input Channel 0');
xlabel('Time (s)');
ylabel('IO0 Input (V)');
grid on;