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

ledDisplay(number)
% ledDisplay(number)
%
% Page 178
% Chapter 6, Activity 3: DISPLAYING DIGITS
%
% This is a MATLAB function that displays a digit on the LED display.
% stampobj is a previously created BasicStamp object. Number is the digit
% to display (number = 0-9). This function needs an argument to run. To
% provide this argument, make sure the Current Folder is the examples
% folder and type ledDisplay(number), replacing number with the number to
% display.
%
% There are a few things to note here. First, because we cannot directly
% access the BASIC Stamp's memory to change multiple inputs at once, we
% have to change them one by one in a for loop. Second, the binary outputs
% are flipped because, in this case, it's more natural to list them from 
% lowest to highest (least significant bit, or LSB, first). Finally,
% there's some numerical manipulation going on to get the digits, pin
% numbers, and lookup table numbers to match up. The latter is because
% MATLAB arrays start at index 1, while the digits 0-9 start at zero
% (obviously enough).

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


function ledDisplay(number)

bs = stamp.BasicStamp('COM4');

outputlist = {'11100111','00100001','11001011', ...
              '01101011','00101101','01101110', ...
              '11101110','00100011','11101111','01101111'};

output = outputlist{number+1}; %the cell array starts at 1 so we need to look at the number+1 entry

for i = 1:8
    bs.writePin(i+7,str2double(output(i))) %write to pins 8-15
end

end

Contact us