Contents

Aaron Klapheck

% Display PS2 Buttons Sent from the BS2 27-Aug-08
clear, clc, home
fprintf('The date and time: %s \n \n', datestr(now))
The date and time: 31-Aug-2008 10:16:01 
 

Program Information

% Purpose
% The purpose of this program is to set up direct communication to the
% Basic Stamp so MATLAB can receive packets of information sent by the BS2.

% Execution
% How this works is that a serial comunication port is opened and data is
% read from it using the fscanf command. This data is then transfered into
% numerical format where its button values are then interpretated using
% Diagram 1 (see bs2 source code for diagram). These buttons are then
% displayed in words for easy reading. The program below is set to receive
% 500 packets of information, to end the program at any time simply hit the
% start button on the PS2 controller.

% Users
% For those who wish to use this code to send messages of their own the
% following information may prove useful. The parts of this code that would
% change depending on individuals software and hardware setup are
% followed by a marking; marking: **(may need to change)**.

Display PS2 Buttons

port = 4; % **(may need to change)**

% Start communication to the Boe-Bot.
[message, s] = StartCommunication(port);

message

rows = 500;

% Receive data and display its meaning.
for x = 1:rows;

% Get button values
[psxThumbL, psxThumbR] = GetPS2Buttons(s);

  switch psxThumbL; % **(may need to change numbers below)**
      case 11111111;
          % disp('No button L')
      case 01111111;
          disp('L arrow')
      case 10111111;
          disp('down arrow')
      case 11011111;
          disp('R arrow')
      case 11101111;
          disp('Up arrow')
      case 11111110;
          disp('Select')
      case 11110111;
          disp('Start')
          break %Stop receiving information from the BS2.
      otherwise
          % disp('multiple buttons being pressed L')
  end % psxThumbL;

  switch psxThumbR; % **(may need to change numbers below)**
      case 11111111;
          % disp('No button R')
      case 01111111;
          disp('square')
      case 10111111;
          disp('X')
      case 11011111;
          disp('circle')
      case 11101111;
          disp('triangle')
      case 11111110;
          disp('L2')
      case 11111101;
          disp('R2')
      case 11111011;
          disp('L1')
      case 11110111;
          disp('R1')
      otherwise
          % disp('multiple buttons being pressed R')
  end %psxThumbR;

end %x = 1:rows;

disp('Program will now end program.')

EndCommunication(s);
message = 

    'This is your Boe-Bot'

Up arrow
Up arrow
Up arrow
Up arrow
L arrow
L arrow
L arrow
L arrow
down arrow
down arrow
down arrow
down arrow
R arrow
R arrow
R arrow
R arrow
square
square
square
square
X
X
X
X
circle
circle
circle
circle
triangle
triangle
triangle
R1
R1
R1
L1
L1
L1
L1
L1
R2
R2
R2
R2
L2
L2
L2
L2
Select
Select
Select
Select
Start
Program will now end program.