function varargout = ECE342GuideDraft(varargin) % ECE342GUIDEDRAFT MATLAB code for ECE342GuideDraft.fig % ECE342GUIDEDRAFT, by itself, creates a new ECE342GUIDEDRAFT or raises the existing % singleton*. % % H = ECE342GUIDEDRAFT returns the handle to a new ECE342GUIDEDRAFT or the handle to % the existing singleton*. % % ECE342GUIDEDRAFT('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in ECE342GUIDEDRAFT.M with the given input arguments. % % ECE342GUIDEDRAFT('Property','Value',...) creates a new ECE342GUIDEDRAFT or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before ECE342GuideDraft_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to ECE342GuideDraft_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 ECE342GuideDraft % Last Modified by GUIDE v2.5 04-Mar-2021 13:10:59 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @ECE342GuideDraft_OpeningFcn, ... 'gui_OutputFcn', @ECE342GuideDraft_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 ECE342GuideDraft is made visible. function ECE342GuideDraft_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 ECE342GuideDraft (see VARARGIN) handles.square = 0; handles.rectangle = 0; handles.circle = 0; handles.triangle = 0; handles.currentData = handles.square; handles.a = arduino('COM9','Nano3','Libraries','Ultrasonic'); handles.u = ultrasonic(handles.a, 'D5', 'D9'); handles.xspot.String = input('Current x: ','s'); %Center of page handles.yspot.String = input('Current y: ','s'); handles.zval.String = floor(readDistance(handles.u)*38*100); %Max Height (0 - 1200) for height %@@@@@@@@@@@@@@@@@@@@@@@@@@@ handles.Alength.String = 0; handles.Blength.String = 0; handles.Clength.String = 0; %@@@@@@@@@@@@@@@@@@@@@@@@@@@ plot(str2double(handles.xspot.String),str2double(handles.yspot.String),'o','MarkerSize',4) xlim([0,1100]) ylim([0,850]) % Choose default command line output for ECE342GuideDraft handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes ECE342GuideDraft wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = ECE342GuideDraft_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; function x1_Callback(hObject, eventdata, handles) % hObject handle to x1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of x1 as text % str2double(get(hObject,'String')) returns contents of x1 as a double str2double(get(hObject, 'String')); % --- Executes during object creation, after setting all properties. function x1_CreateFcn(hObject, eventdata, handles) % hObject handle to x1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function x2_Callback(hObject, eventdata, handles) % hObject handle to x2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of x2 as text % str2double(get(hObject,'String')) returns contents of x2 as a double str2double(get(hObject, 'String')); % --- Executes during object creation, after setting all properties. function x2_CreateFcn(hObject, eventdata, handles) % hObject handle to x2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function y2_Callback(hObject, eventdata, handles) % hObject handle to y2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of y2 as text % str2double(get(hObject,'String')) returns contents of y2 as a double str2double(get(hObject, 'String')); % --- Executes during object creation, after setting all properties. function y2_CreateFcn(hObject, eventdata, handles) % hObject handle to y2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function y1_Callback(hObject, eventdata, handles) % hObject handle to y1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of y1 as text % str2double(get(hObject,'String')) returns contents of y1 as a double str2double(get(hObject, 'String')); % --- Executes during object creation, after setting all properties. function y1_CreateFcn(hObject, eventdata, handles) % hObject handle to y1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pointstart. function pointstart_Callback(hObject, eventdata, handles) % hObject handle to pointstart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = handles.a; u = handles.u; x1_string = get(handles.x1,'string'); x1 = str2double(get(handles.x1,'string')); y1_string = get(handles.y1,'string'); y1 = str2double(get(handles.y1,'string')); x2_string = get(handles.x2,'string'); x2 = str2double(get(handles.x2,'string')); y2_string = get(handles.y2,'string'); y2 = str2double(get(handles.y2,'string')); if x1<0|x1>1100|x2<0|x2>1100|y1<0|y1>850|y2<0|y2>850 error_disp = ['A variable is out of bounds']; disp(error_disp) else distance = sqrt((x2-x1)^2+(y2-y1)^2); slope = (y2-y1)/(x2-x1); proXdata = linspace(x1,x2,floor(distance/15)); proYdata = linspace(y1,y2,floor(distance/15)); point_disp = ['Traveled from (', x1_string, ',', y1_string, ') to (', x2_string, ',', y2_string, ')']; disp(point_disp) plot(proXdata, proYdata,'o','MarkerSize',4) xlim([0,1100]) ylim([0,850]) hold on plot(proXdata(floor(distance/15)),proYdata(floor(distance/15)),'o','MarkerSize',6) hold off handles.xspot.String = proXdata(floor(distance/15)); handles.yspot.String = proYdata(floor(distance/15)); end guidata(hObject, handles) % --- Executes on button press in shapestart. function shapestart_Callback(hObject, eventdata, handles) % hObject handle to shapestart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = handles.a; u = handles.u; length_string = get(handles.lengthbox,'string'); length = str2double(get(handles.lengthbox,'string')); width_string = get(handles.widthbox,'string'); width = str2double(get(handles.widthbox,'string')); radius_string = get(handles.radiusbox,'string'); radius = str2double(get(handles.radiusbox,'string')); if radius<0|radius>425|length<0|length>850|width<0|width>1100 error_disp = ['A variable is out of bounds']; disp(error_disp) else str = get(handles.shapemenu, 'String'); val = get(handles.shapemenu, 'Value'); switch str{val} case 'Square (width)'; squaredisp = ['Square of side width: ', width_string]; disp(squaredisp) %Command Window Message n = floor(width/60); xs_bottom_edge = linspace(floor(550-(width/2)), floor(550+(width/2)), n); ys_bottom_edge = linspace(floor(425-(width/2)), floor(425-(width/2)), n); xs_right_edge = linspace(floor(550+(width/2)), floor(550+(width/2)), n); ys_right_edge = linspace(floor(425-(width/2)), floor(425+(width/2)), n); xs_top_edge = linspace(floor(550+(width/2)), floor(550-(width/2)), n); ys_top_edge = linspace(floor(425+(width/2)), floor(425+(width/2)), n); xs_left_edge = linspace(floor(550-(width/2)), floor(550-(width/2)), n); ys_left_edge = linspace(floor(425+(width/2)), floor(425-(width/2)), n); xsquare = [xs_bottom_edge, xs_right_edge, xs_top_edge, xs_left_edge]; ysquare = [ys_bottom_edge, ys_right_edge, ys_top_edge, ys_left_edge]; hold off plot(xsquare, ysquare,':','MarkerSize',2) xlim([0,1100]) ylim([0,850]) graph_function(a, u, str2double(handles.xspot.String), str2double(handles.yspot.String), xs_bottom_edge(1), ys_bottom_edge(1)); up_down(a, u, 0, 1); pause(0.4); graph_function(a, u, xs_bottom_edge(1), ys_bottom_edge(1), xs_right_edge(1), ys_right_edge(1)); pause(0.2); graph_function(a, u, xs_right_edge(1), ys_right_edge(1), xs_top_edge(1), ys_top_edge(1)); pause(0.2); graph_function(a, u, xs_top_edge(1), ys_top_edge(1), xs_left_edge(1)*1.1, ys_left_edge(1)); pause(0.2); graph_function(a, u, xs_left_edge(1), ys_left_edge(1), xs_bottom_edge(1), ys_bottom_edge(1)); up_down(a, u, 1, 0); handles.xspot.String = xsquare(4*n); handles.yspot.String = ysquare(4*n); hold off clear a %================================================================================================ case 'Rectangle (len, width)'; rectdisp = ['Rectangle of length: ', length_string, ' and width: ', width_string]; disp(rectdisp) %Command Window Message nl = floor(length/10); nw = floor(width/10); xr_bottom_edge = linspace(floor(550-(width/2)), floor(550+(width/2)), nw); yr_bottom_edge = linspace(floor(425-(length/2)), floor(425-(length/2)), nw); xr_right_edge = linspace(floor(550+(width/2)), floor(550+(width/2)), nl); yr_right_edge = linspace(floor(425-(length/2)), floor(425+(length/2)), nl); xr_top_edge = linspace(floor(550+(width/2)), floor(550-(width/2)), nw); yr_top_edge = linspace(floor(425+(length/2)), floor(425+(length/2)), nw); xr_left_edge = linspace(floor(550-(width/2)), floor(550-(width/2)), nl); yr_left_edge = linspace(floor(425+(length/2)), floor(425-(length/2)), nl); xrect = [xr_bottom_edge, xr_right_edge, xr_top_edge, xr_left_edge]; yrect = [yr_bottom_edge, yr_right_edge, yr_top_edge, yr_left_edge]; plot(xrect, yrect,':','MarkerSize',2) xlim([0,1100]) ylim([0,850]) graph_function(a, u, str2double(handles.xspot.String), str2double(handles.yspot.String), xr_bottom_edge(1), yr_bottom_edge(1)); up_down(a, u, 0, 1); pause(0.4); graph_function(a, u, xr_bottom_edge(1), yr_bottom_edge(1), xr_right_edge(1), yr_right_edge(1)); pause(0.2); graph_function(a, u, xr_right_edge(1), yr_right_edge(1), xr_top_edge(1), yr_top_edge(1)); pause(0.2); graph_function(a, u, xr_top_edge(1), yr_top_edge(1), xr_left_edge(1), yr_left_edge(1)); pause(0.2); graph_function(a, u, xr_left_edge(1), yr_left_edge(1), xr_bottom_edge(1), yr_bottom_edge(1)); up_down(a, u, 1, 0); % for i = 1:1:(2*nw+2*nl) % hold on % plot(xrect(i),yrect(i),'bo','MarkerSize',2) % xlim([0,1100]) % ylim([0,850]) % handles.xspot.String = floor(xrect(i)); % handles.yspot.String = floor(yrect(i)); % % %@@@@@@@@@@@@@@@@@@@@@@@@@@@ % handles.Alength.String = floor(sqrt((1250+xrect(i))^2+(600+yrect(i))^2))/100; % handles.Blength.String = floor(sqrt((550-xrect(i))^2+(2518-yrect(i))^2))/100; % handles.Clength.String = floor(sqrt((2250-xrect(i))^2+(600+yrect(i))^2))/100; % %@@@@@@@@@@@@@@@@@@@@@@@@@@@ % % pause(0.100); % % end % hold off hold off handles.xspot.String = xrect(2*nl+2*nw); handles.yspot.String = yrect(2*nl+2*nw); case 'Circle (rad)'; circledisp = ['Circle of radius: ', radius_string]; disp(circledisp) %Command Window Message angle = 0:70/radius:2*pi; %Adjust Spacing xcirc = radius*cos(angle) + 550; ycirc = radius*sin(angle) + 425; plot(xcirc, ycirc,':','MarkerSize',2) xlim([0,1100]) ylim([0,850]) n = max(size(angle)) handles.xspot.String = xcirc(n); handles.yspot.String = ycirc(n); hold off clear a % plot(xcirc(i),ycirc(i),'bo','MarkerSize',2) % xlim([0,1100]) % ylim([0,850]) % handles.xspot.String = floor(xcirc(i)); % handles.yspot.String = floor(ycirc(i)); % % %@@@@@@@@@@@@@@@@@@@@@@@@@@@ % handles.Alength.String = floor(sqrt((1250+xcirc(i))^2+(600+ycirc(i))^2))/100; % handles.Blength.String = floor(sqrt((550-xcirc(i))^2+(2518-ycirc(i))^2))/100; % handles.Clength.String = floor(sqrt((2250-xcirc(i))^2+(600+ycirc(i))^2))/100; % %@@@@@@@@@@@@@@@@@@@@@@@@@@@ % % pause(0.100); case 'Triangle (len, width)'; triangledisp = ['Triangle of baselength: ', length_string, ' and height: ', width_string]; disp(triangledisp) %Command Window Message nl = floor(length/10); nw = floor(width/12); xt_bottom_edge = linspace(floor(550-(width/2)), floor(550+(width/2)), nw); yt_bottom_edge = linspace(floor(425-(length/2)), floor(425-(length/2)), nw); xt_right_edge = linspace(floor(550+(width/2)), floor(550), nl); yt_right_edge = linspace(floor(425-(length/2)), floor(425+(length/2)), nl); xt_left_edge = linspace(floor(550), floor(550-(width/2)), nl); yt_left_edge = linspace(floor(425+(length/2)), floor(425-(length/2)), nl); xtri = [xt_bottom_edge, xt_right_edge, xt_left_edge]; ytri = [yt_bottom_edge, yt_right_edge, yt_left_edge]; plot(xtri,ytri,':','MarkerSize',2) xlim([0,1100]) ylim([0,850]) graph_function(a, u, str2double(handles.xspot.String), str2double(handles.yspot.String), xt_bottom_edge(1), yt_bottom_edge(1)); up_down(a, u, 0, 1); pause(0.4); graph_function(a, u, xt_bottom_edge(1), yt_bottom_edge(1), xt_right_edge(1), yt_right_edge(1)); pause(0.2); graph_function(a, u, xt_right_edge(1), yt_right_edge(1), xt_left_edge(1), yt_left_edge(1)); pause(0.2); graph_function(a, u, xt_left_edge(1), yt_left_edge(1), xt_bottom_edge(1), yt_bottom_edge(1)); up_down(a, u, 1, 0); handles.xspot.String = xtri(2*nl+nw); handles.yspot.String = ytri(2*nl+nw); % for i = 1:1:(nw+2*nl) % hold on % plot(xtri(i),ytri(i),'bo','MarkerSize',2) % xlim([0,1100]) % ylim([0,850]) % handles.xspot.String = floor(xtri(i)); % handles.yspot.String = floor(ytri(i)); % % %@@@@@@@@@@@@@@@@@@@@@@@@@@@ % handles.Alength.String = floor(sqrt((1250+xtri(i))^2+(600+ytri(i))^2))/100; % handles.Blength.String = floor(sqrt((550-xtri(i))^2+(2518-ytri(i))^2))/100; % handles.Clength.String = floor(sqrt((2250-xtri(i))^2+(600+ytri(i))^2))/100; % %@@@@@@@@@@@@@@@@@@@@@@@@@@@ % % pause(0.100); % % end hold off end end % --- Executes on selection change in shapemenu. function shapemenu_Callback(hObject, eventdata, handles) % hObject handle to shapemenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns shapemenu contents as cell array % contents{get(hObject,'Value')} returns selected item from shapemenu str = get(hObject, 'String'); val = get(hObject, 'Value'); switch str{val} case 'square'; handles.currentdata = handles.shapestart; case 'rectangle'; handles.currentdata = handles.shapestart; case 'circle'; handles.currentdata = handles.shapestart; case 'triangle'; handles.currentdata = handles.shapestart; end % --- Executes during object creation, after setting all properties. guidata(hObject, handles); function shapemenu_CreateFcn(hObject, eventdata, handles) % hObject handle to shapemenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function lengthbox_Callback(hObject, eventdata, handles) % hObject handle to lengthbox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of lengthbox as text % str2double(get(hObject,'String')) returns contents of lengthbox as a double % --- Executes during object creation, after setting all properties. function lengthbox_CreateFcn(hObject, eventdata, handles) % hObject handle to lengthbox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function widthbox_Callback(hObject, eventdata, handles) % hObject handle to widthbox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of widthbox as text % str2double(get(hObject,'String')) returns contents of widthbox as a double % --- Executes during object creation, after setting all properties. function widthbox_CreateFcn(hObject, eventdata, handles) % hObject handle to widthbox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function radiusbox_Callback(hObject, eventdata, handles) % hObject handle to radiusbox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of radiusbox as text % str2double(get(hObject,'String')) returns contents of radiusbox as a double % --- Executes during object creation, after setting all properties. function radiusbox_CreateFcn(hObject, eventdata, handles) % hObject handle to radiusbox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function gcodebox_Callback(hObject, eventdata, handles) % hObject handle to gcodebox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of gcodebox as text % str2double(get(hObject,'String')) returns contents of gcodebox as a double % --- Executes during object creation, after setting all properties. function gcodebox_CreateFcn(hObject, eventdata, handles) % hObject handle to gcodebox (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white') end % --- Executes on button press in gcodestart. function gcodestart_Callback(hObject, eventdata, handles) % hObject handle to gcodestart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = handles.a; u = handles.u; gcodestring = get(handles.gcodebox,'string'); gcodenum = []; i = 1; while gcodestring(i) ~= ' ' gcodenum = [gcodenum, gcodestring(i)]; i = i + 1; if i-1 == length(gcodestring) %Accounts for commands without space after break end end switch gcodenum case 'G00'; disp('G-Code is G00') xstring = []; i = i + 1; while gcodestring(i) ~= ' ' xstring = [xstring, gcodestring(i)]; i = i + 1; end xstring; %checkpoint xstringval = []; for k = i-length(xstring)+1:i-1 xstringval = [xstringval, gcodestring(k)]; end xstringval; %checkpoint xval = str2double(xstringval) ystring = []; i = i + 1; for j = i:length(gcodestring) ystring = [ystring, gcodestring(j)]; end ystring; ystringval = []; for k = j-length(ystring)+2:j ystringval = [ystringval, gcodestring(k)]; end ystringval; %checkpoint yval = str2double(ystringval) %================================================= %GRAPHING xprev = str2double(handles.xspot.String) yprev = str2double(handles.yspot.String) if handles.gcodemode.String == 'Absolute Mode' xval = xval; yval = yval; else xval = xval + xprev; yval = yval + yprev; end up_down(a, u, 0, 1); graph_function(a, u, xprev, yprev, xval, yval); up_down(a, u, 1, 0); handles.xspot.String = xval; handles.yspot.String = yval; case 'G01'; disp('G-Code is G01') xstring = []; i = i + 1; while gcodestring(i) ~= ' ' xstring = [xstring, gcodestring(i)]; i = i + 1; end xstring; %checkpoint xstringval = []; for k = i-length(xstring)+1:i-1 xstringval = [xstringval, gcodestring(k)]; end xstringval; %checkpoint xval = str2double(xstringval); %Value of X ystring = []; i = i + 1; while gcodestring(i) ~= ' ' ystring = [ystring, gcodestring(i)]; i = i + 1; end ystringval = []; for k = i-length(ystring)+1:i-1 ystringval = [ystringval, gcodestring(k)]; end ystringval; %checkpoint yval = str2double(ystringval); fstring = []; for j = i+1:length(gcodestring) fstring = [fstring, gcodestring(j)]; end fstring; fstringval = []; for k = i+2:length(gcodestring) fstringval = [fstringval, gcodestring(k)]; end fstringval; %checkpoint fval = str2double(fstringval); %================================================== %GRAPHING xprev = str2double(handles.xspot.String); yprev = str2double(handles.yspot.String); if handles.gcodemode.String == 'Absolute Mode' xval = xval; yval = yval; else xval = xval + xprev; yval = yval + yprev; end up_down(a, u, 0, 1); graph_function(a, u, xprev, yprev, xval, yval); up_down(a, u, 1, 0); handles.xspot.String = xval; handles.yspot.String = yval; case 'G20'; disp('Units changed to inches') case 'G21'; disp('Units changed to millimeters') case 'G90'; disp('G90') disp('Absolute Mode') handles.gcodemode.String = 'Absolute Mode'; case 'G91'; disp('Relative Mode') handles.gcodemode.String = 'Relative Mode'; case 'M02'; disp('Program Ended') clear a closereq(); case 'M2'; disp('Program Ended') clear a closereq(); case 'M06'; disp('Tool Change') up_down(a, u, 1, 0); graph_function(a, u, str2double(handles.xspot.String), str2double(handles.yspot.String), 550, 425); handles.xspot.String = 550; handles.yspot.String = 425; plot(550,425,'o','MarkerSize',2); xlim([0,1100]) ylim([0,850]) case 'M6'; disp('Tool Change') up_down(a, u, 1, 0); graph_function(a, u, str2double(handles.xspot.String), str2double(handles.yspot.String), 550, 425); handles.xspot.String = 550; handles.yspot.String = 425; plot(550,425,'o','MarkerSize',2); xlim([0,1100]) ylim([0,850]) case 'M72'; disp('Ta Da!') %[y, Fs] = audioread('SOUND EFFECT TADA.mp3'); %player = audioplayer(y, Fs); %play(player); fullname = 'SOUND EFFECT TADA.mp3'; %change as required try [y, Fs] = audioread(fullname); PO=audioplayer(y,Fs); % Play audio playblocking(PO) catch ME uiwait(msgbox('Could not open that file with audioread')); end end % --- 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) disp('Program Ended') clear handles.a closereq();