how can i solve Error in gui_mainfcn

6 views (last 30 days)
function varargout = Illumination001(varargin)
% ILLUMINATION001 MATLAB code for Illumination001.fig
% ILLUMINATION001, by itself, creates a new ILLUMINATION001 or raises the existing
% singleton*.
%
% H = ILLUMINATION001 returns the handle to a new ILLUMINATION001 or the handle to
% the existing singleton*.
%
% ILLUMINATION001('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ILLUMINATION001.M with the given input arguments.
%
% ILLUMINATION001('Property','Value',...) creates a new ILLUMINATION001 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Illumination001_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Illumination001_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 Illumination001
% Last Modified by GUIDE v2.5 22-Jul-2016 15:51:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Illumination001_OpeningFcn, ...
'gui_OutputFcn', @Illumination001_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 Illumination001 is made visible.
function Illumination001_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 Illumination001 (see VARARGIN)
% Choose default command line output for Illumination001
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Illumination001 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Illumination001_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;
clear a;
global delay;
delay=0.5;
global a;
a = arduino('COM7');
for i=3:10
a.pinMode(i,'output');
end
for i=3:10
a.digitalWrite(i,1);
end
% --- Executes on button press in Pattern1.
function Pattern1_Callback(hObject, eventdata, handles)
% hObject handle to Pattern1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global delay;
while 1
for l=3:10
a.digitalWrite(l,1);
end
for i=1:5
for n=3:10
a.digitalWrite(n,0);
pause(delay);
a.digitalWrite(n,1);
pause(delay);
end
end
end
% --- Executes on button press in Pattern2.
function Pattern2_Callback(hObject, eventdata, handles)
% hObject handle to Pattern2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global delay;
while 1
for m=3:10
a.digitalWrite(m,1);
end
for i=3:10
for j=3:i
a.digitalWrite(j,0);
pause(delay);
end
for m=3:10
a.digitalWrite(m,1);
end
pause(delay);
end
end
% --- Executes on button press in Pattern3.
function Pattern3_Callback(hObject, eventdata, handles)
% hObject handle to Pattern3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global delay;
while 1
for j=3:10
a.digitalWrite(j,1);
end
pause(delay);
for k=3:10
a.digitalWrite(k,0);
pause(delay);
end
for k=3:10
a.digitalWrite(k,1);
pause(delay);
end
end
% --- Executes on button press in FAST.
function FAST_Callback(hObject, eventdata, handles)
% hObject handle to FAST (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global delay;
delay=0.2;
% --- Executes on button press in SLOW.
function SLOW_Callback(hObject, eventdata, handles)
% hObject handle to SLOW (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global delay;
delay=0.8;
% --- Executes on button press in Pattern4.
function Pattern4_Callback(hObject, eventdata, handles)
% hObject handle to Pattern4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global delay;
while 1
for i=3:10
a.digitalWrite(i,1);
end
for n=3:10
a.digitalWrite(n,0);
pause(delay);
a.digitalWrite(n,1);
pause(delay);
end
for n=10:-1:3
a.digitalWrite(n,0);
pause(delay);
a.digitalWrite(n,1);
pause(delay);
end
end
% --- Executes on button press in NORMAL.
function NORMAL_Callback(hObject, eventdata, handles)
% hObject handle to NORMAL (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global delay;
delay=0.5;
% --- Executes on button press in Pattern5.
function Pattern5_Callback(hObject, eventdata, handles)
% hObject handle to Pattern5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global delay;
while 1
for m=3:10
a.digitalWrite(m,1);
end
for i=3:10
for j=3:i
a.digitalWrite(j,0);
pause(delay);
end
end
for m=10:-1:3
for j=10:-1:m
a.digitalWrite(j,1);
pause(delay);
end
end
pause(delay);
end
% --- Executes on button press in STOP.
function STOP_Callback(hObject, eventdata, handles)
% hObject handle to STOP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
clear all
Error using Illumination001>Illumination001_OutputFcn (line 78)
MATLAB connection to Arduino Uno at COM7 exists in your workspace. To create a new connection, clear the existing object.
Error in gui_mainfcn (line 264)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
Error in Illumination001 (line 42)
gui_mainfcn(gui_State, varargin{:});

Answers (1)

Walter Roberson
Walter Roberson on 23 May 2022
You previously crashed during execution so STOP_Callback did not get executed so "clear all" did not get executed. You need to manually
clear global
You should consider putting in protections such as an onCleanup or CloseRequestFcn, and your initialization code should check whether "a" is empty before trying to create the new connection.
  9 Comments
abdelgawad abdelgawad
abdelgawad abdelgawad on 26 May 2022
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Illumination001('Pattern1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Walter Roberson
Walter Roberson on 27 May 2022
You could use an old version of MATLAB with the Legacy Arduino package so that you did not need to rewrite the arduino interface.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!