MATLAB Support Package for Parallax BASIC Stamp
25 Jul 2011
22 Aug 2011)
MATLAB library for communicating with a BASIC Stamp 2 and Board of Education (BoE) kit
% 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.
bs = stamp.BasicStamp('COM4'); %Change to your BS2 serial port
for i = 1:50
time = bs.getRCTime(7,1);
fprintf('time = %d\n',time);