function varargout = TesteLedGUISimples(varargin) % TESTELEDGUISIMPLES MATLAB code for TesteLedGUISimples.fig % TESTELEDGUISIMPLES, by itself, creates a new TESTELEDGUISIMPLES or raises the existing % singleton*. % % H = TESTELEDGUISIMPLES returns the handle to a new TESTELEDGUISIMPLES or the handle to % the existing singleton*. % % TESTELEDGUISIMPLES('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TESTELEDGUISIMPLES.M with the given input arguments. % % TESTELEDGUISIMPLES('Property','Value',...) creates a new TESTELEDGUISIMPLES or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before TesteLedGUISimples_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to TesteLedGUISimples_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help TesteLedGUISimples % Last Modified by GUIDE v2.5 18-Oct-2018 21:05:15 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @TesteLedGUISimples_OpeningFcn, ... 'gui_OutputFcn', @TesteLedGUISimples_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before TesteLedGUISimples is made visible. function TesteLedGUISimples_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to TesteLedGUISimples (see VARARGIN) % Choose default command line output for TesteLedGUISimples handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes TesteLedGUISimples wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = TesteLedGUISimples_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) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in BotLEDVermelho. function BotLEDVermelho_Callback(hObject, eventdata, handles) % hObject handle to BotLEDVermelho (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tep fwrite(tep,'R'); %Print character ‘a’ to the serial port disp('Charater sent to Serial Port is "R".'); % --- Executes on button press in BotLEDVerde. function BotLEDVerde_Callback(hObject, eventdata, handles) % hObject handle to BotLEDVerde (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tep fwrite(tep,'G'); %Print character ‘a’ to the serial port disp('Charater sent to Serial Port is "G".'); % --- Executes on button press in BotStart. function BotStart_Callback(hObject, eventdata, handles) % hObject handle to BotStart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clc global tep; disp('Welcome to TEP'); disp(''); disp('www.TheEngineeringProjects.com'); disp(''); tep=serial('COM3'); % assign serial port object set(tep, 'BaudRate', 9600); % set BaudRate to 9600 set(tep, 'Parity', 'none'); % set Parity Bit to None set(tep, 'DataBits', 8); % set DataBits to 8 set(tep, 'StopBit', 1); % set StopBit to 1 %display the properties of serial port object in MATLAB Window disp(get(tep,{'Type','Name','Port','BaudRate','Parity','DataBits','StopBits'})); fopen(tep); % Open Serial Port Object % apaga botão start set(handles.BotStart, 'Enable', 'off'); % mostra todos os outros elementos da tela set(handles.BotStop, 'Enable', 'on'); set(handles.PanelLEDs, 'Visible', 'on'); set(handles.BotLEDVermelho, 'Visible', 'on'); set(handles.BotLEDVerde, 'Visible', 'on'); set(handles.BotLEDApaga, 'Visible', 'on'); set(handles.PanelUltraSom, 'Visible', 'on'); set(handles.BotUltraSom, 'Visible', 'on'); set(handles.TextDistancia, 'Visible', 'on'); set(handles.TextUnidades, 'Visible', 'on'); % --- Executes on button press in BotStop. function BotStop_Callback(hObject, eventdata, handles) % hObject handle to BotStop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tep; fclose(tep); % mostra botão start set(handles.BotStart, 'Enable', 'on'); % apaga todos os outros elementos da tela set(handles.BotStop, 'Enable', 'off'); set(handles.PanelLEDs, 'Visible', 'off'); set(handles.BotLEDVermelho, 'Visible', 'off'); set(handles.BotLEDVerde, 'Visible', 'off'); set(handles.BotLEDApaga, 'Visible', 'off'); set(handles.PanelUltraSom, 'Visible', 'off'); set(handles.BotUltraSom, 'Visible', 'off'); set(handles.TextDistancia, 'Visible', 'off'); set(handles.TextUnidades, 'Visible', 'off'); % --- Executes on button press in BotLEDApaga. function BotLEDApaga_Callback(hObject, eventdata, handles) % hObject handle to BotLEDApaga (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tep fwrite(tep,'S'); %Print character ‘a’ to the serial port disp('Charater sent to Serial Port is "S".'); % --- Executes on button press in BotUltraSom. function BotUltraSom_Callback(hObject, eventdata, handles) % hObject handle to BotUltraSom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tep while 1 set(handles.TextDistancia, 'String', num2str( round(str2num( fgets(tep) )*10)/10, '%5.1f\n')); pause(0.0250); end