Professional Documents
Culture Documents
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
delete(instrfind({'Port'},{'COM12'}))
clear a;
global a;
a = serial('COM12', 'BaudRate', 9600); % setup comport
%fopen(a); % Open comport
cla(handles.graph);
set(handles.ON_button,'BackgroundColor','green');
set(handles.OFF_button,'BackgroundColor','red');
% --- Outputs from this function are returned to the command line.
function varargout = distance_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fopen(a);
configurePin(a,'D6','DigitalInput');
pinMode = configurePin(a,'D6');
while ~(handles.stop_now)
x=x+1;
data=fscanf(a);
[data1] = strtok(data);
y1(x)=str2num(data1);
disp_y1 = num2str(y1(x));
set(handles.distance,'string',disp_y1);
drawnow;
axes(handles.graph);
plot(y1,'b-','linewidth',2)
title('Distance');
xlabel('Time');
ylabel('Distance (cm)');
ylim([0 0.2])
pause(0.01);
handles = guidata(hObject);
end