Code covered by the BSD License  

Highlights from
MATLAB Support Package for Parallax BASIC Stamp

image thumbnail

MATLAB Support Package for Parallax BASIC Stamp

by

 

25 Jul 2011 (Updated )

MATLAB library for communicating with a BASIC Stamp 2 and Board of Education (BoE) kit

measureRot()
% measureRot
%
% Page 150
% Chapter 5, Activity 3: READING THE DIAL WITH THE BASIC STAMP
%
% Note that this is a function, not a script. A function has its own scope,
% meaning that this will not affect the variables in the workspace. This
% also means that an error in the code won't leave an undeleted BasicStamp
% object that could cause errors elsewhere. Generally, functions are
% preferable to scripts for these reasons.
%
% This function will time out after 50 readings (about 5 seconds), taking a
% measurement every 100ms.
%
% Try replacing the potentiometer with a phototransistor (see chapter 7) to
% measure light levels instead of rotation.

%   MATLAB Support Package for BASIC Stamp
%   Version 1.0
%   Copyright 2011 The MathWorks, Inc.


function measureRot()

bs = stamp.BasicStamp('COM4'); %Change to your BS2 serial port

for i = 1:50
    bs.writePin(7,1);
    pause(.1);
    time = bs.getRCTime(7,1);
    fprintf('time = %d\n',time);
end

delete(bs);

end

Contact us