% -------------------------------------------------------------------------
% ECE476 Final Project Run
% -------------------------------------------------------------------------

function searchBot(mode, angle, distance)

% do error-checking for distance
if distance > 120
    distance = 120;
elseif distance < -120
    distance = -120;
end

% do error-checking for angle
angle = rem(angle, 360);
if (angle < -180)
    angle = angle + 360;
elseif (angle > 180)
    angle = angle - 360;
end
    
% write to file and send file to car
fid = fopen('carcontrol.txt', 'w');
fprintf(fid, '%d\n %d\n %d\n', mode, ceil(angle/2), distance);
fclose(fid);

% call car control program
system('PCtoPDAconnection.exe');