I need help to solve this problem, I don't understand why it's not working

조회 수: 1 (최근 30일)
function varargout = Classroom_security(varargin)
%CLASSROOM_SECURITY MATLAB code file for Classroom_security.fig
% CLASSROOM_SECURITY, by itself, creates a new CLASSROOM_SECURITY or raises the existing
% singleton*.
%
% H = CLASSROOM_SECURITY returns the handle to a new CLASSROOM_SECURITY or the handle to
% the existing singleton*.
%
% CLASSROOM_SECURITY('Property','Value',...) creates a new CLASSROOM_SECURITY using the
% given property value pairs. Unrecognized properties are passed via
% varargin to Classroom_security_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% CLASSROOM_SECURITY('CALLBACK') and CLASSROOM_SECURITY('CALLBACK',hObject,...) call the
% local function named CALLBACK in CLASSROOM_SECURITY.M with the given input
% arguments.
%
% *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 Classroom_security
% Last Modified by GUIDE v2.5 04-Feb-2023 10:12:32
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Classroom_security_OpeningFcn, ...
'gui_OutputFcn', @Classroom_security_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 Classroom_security is made visible.
function Classroom_security_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for Classroom_security
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Classroom_security wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Classroom_security_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 Classroom.
function Classroom_Callback(hObject, eventdata, handles)
% hObject handle to Classroom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Fenetre (Infraction)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
a = arduino('COM8', 'UNO','Libraries',{'Ultrasonic','Servo'})
configurePin(a,'D11','Tone')
while 1==1
mouv=readDigitalPin(a,'D10')
if mouv==1
playTone(a,'D11',1200,1);
else
playTone(a,'D11',1200,0)
end
end
% Porte de la classe
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
a = arduino('COM8', 'UNO','Libraries',{'Ultrasonic','Servo'})
servo1=servo(a,'D10')
sensor= ultrasonic(a,'D12','D13');
while 1==1
x=(readDistance(sensor))*100
if x<10
writePosition(servo1, 1)
pause(5)
else
writePosition(servo1, 0)
end
end
% Capteur de gaz
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
a=arduino('COM6','UNO','Libraries',{'servo'})
servo1=servo(a,'D8')
while 1==1
gaz=readDigitalPin(a,'A0')
if gaz==1
writePosition(servo1, .7)
else
writePosition(servo1, 0)
end
end
% Capteur de flamme
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
a = arduino('COM8', 'UNO','Libraries',{'Ultrasonic','Servo'})
capteurflamme=readDigitalPin(a,'D8')
configurePin(a,'D11','Tone')
servo1=servo(a,'D4')
servo2=servo(a,'D5')
while 1==1
capteurflamme=readDigitalPin(a,'D8')
if capteurflamme==1
writePosition(servo1, 1)
writePosition(servo2, 1) % fenetre ouverte
playTone(a,'D11',1200,1)% siréne allumée
writeDigitalPin(a,'D7',1);
pause(5)
else
writePosition(servo1, 0)% fenetre fermée
writePosition(servo2, 0)
playTone(a,'D11',1200,0)% siréne éteinte
writeDigitalPin(a,'D7',0);
end
end
  댓글 수: 1
Birane Abdoulaye Ba
Birane Abdoulaye Ba 2023년 2월 4일
Voici ce que ca me montre dans la commande window
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Classroom_security (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Classroom_security('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 2월 4일
configure the arduino and servos once in Classroom_security_OpeningFcn
not in every callback.
Also use try/catch in case the arduino cannot be reached (perhaps because a connection is still hanging around from last time you ran, as you do not remove the connection after you are done with it)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by