function total()
global x;
global y;
global z;
global Z;
Z = 0;

s2 = serial('COM2', 'BaudRate', 9600,'databits',7, 'timeout',10, 'stopbit', 1);
fopen(s2);

while Z == 0;

    if z == 1
    fwrite(s2,x)
    fwrite(s2,y)
    z = 0;
    end

ind = fread(s2,500);        % fread(s2,# of points)
data  = (ind -1 ) * 5 ;     % -1 for 0's correction, 5x for resolution of RPM
time = (1:1:500)';          % (1:1:# of points)'
time = time / 500;
plot (time,data, '-');
xlabel('Time [ms]');
ylabel('RPM');
title('Actual Data');
axis([0,500/500,0,700]);    % X/500 for 2ms for time between data received
pause (.1)

end
fclose(s2);


end