%joytestloop.m
%continuously display (X,Y,Z) position and state of buttons 1-8
%Exit via ctrl-C from keyboard

%initialize JoyMEX interface
clear JoyMEX;
JoyMEX('init',0);

%display banner
fprintf('\nJoyMEX test:   ctrl-C to exit   ');
pause(2)
fprintf('\n');

%%%%%%%%%%%%%%%%
% display loop %
%%%%%%%%%%%%%%%%
while (1)
   %query joystick
   %positions(1) and (2): Main joystick (X,Y) (range: +/- 0.0-1.0)
   %positions(4) and (5): (Rx,Ry) position
   %positions(3):         Z-axis slider position
   %buttons(1:128):       Button states (on/off; logical array)
   [positions, buttons] = JoyMEX(0);
   
   %echo (X,Y) position to console
   fprintf('(X,Y,Z): %0.4f, %0.4f %0.4f   buttons[1:8] %d %d %d %d %d %d %d %d\n', ...
       positions(1),positions(2),positions(3),buttons(1:8));
   
   drawnow;
end

