classdef comunArdTest < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure        matlab.ui.Figure
        PinOffButton_4  matlab.ui.control.Button
        PinOnButton_4   matlab.ui.control.Button
        PinOffButton_3  matlab.ui.control.Button
        PinOnButton_3   matlab.ui.control.Button
        PinOffButton_2  matlab.ui.control.Button
        PinOnButton_2   matlab.ui.control.Button
        offButton       matlab.ui.control.Button
        ConnectButton   matlab.ui.control.Button
        PinOffButton    matlab.ui.control.Button
        PinOnButton     matlab.ui.control.Button
    end

    
    properties (Access = public)
        x = serial("COM3","BaudRate",115200); % Description
    end

    

    % Callbacks that handle component events
    methods (Access = private)

        % Button pushed function: ConnectButton
        function ConnectButtonPushed(app, event)
            fopen(app.x);
        end

        % Button pushed function: PinOnButton
        function PinOnButtonPushed(app, event)
%             clear x
%             x =
            fprintf(app.x,1);
        end

        % Button pushed function: PinOffButton
        function PinOffButtonPushed(app, event)
            fprintf(app.x,0);
        end

        % Button pushed function: offButton
        function offButtonPushed(app, event)
            fclose(app.x);
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 640 480];
            app.UIFigure.Name = 'MATLAB App';

            % Create PinOnButton
            app.PinOnButton = uibutton(app.UIFigure, 'push');
            app.PinOnButton.ButtonPushedFcn = createCallbackFcn(app, @PinOnButtonPushed, true);
            app.PinOnButton.Position = [107 327 165 62];
            app.PinOnButton.Text = 'PinOn';

            % Create PinOffButton
            app.PinOffButton = uibutton(app.UIFigure, 'push');
            app.PinOffButton.ButtonPushedFcn = createCallbackFcn(app, @PinOffButtonPushed, true);
            app.PinOffButton.Position = [370 327 165 62];
            app.PinOffButton.Text = 'PinOff';

            % Create ConnectButton
            app.ConnectButton = uibutton(app.UIFigure, 'push');
            app.ConnectButton.ButtonPushedFcn = createCallbackFcn(app, @ConnectButtonPushed, true);
            app.ConnectButton.Position = [271 424 100 22];
            app.ConnectButton.Text = 'Connect';

            % Create offButton
            app.offButton = uibutton(app.UIFigure, 'push');
            app.offButton.ButtonPushedFcn = createCallbackFcn(app, @offButtonPushed, true);
            app.offButton.Position = [271 43 100 22];
            app.offButton.Text = 'off';

            % Create PinOnButton_2
            app.PinOnButton_2 = uibutton(app.UIFigure, 'push');
            app.PinOnButton_2.Position = [107 250 165 62];
            app.PinOnButton_2.Text = 'PinOn';

            % Create PinOffButton_2
            app.PinOffButton_2 = uibutton(app.UIFigure, 'push');
            app.PinOffButton_2.Position = [370 250 165 62];
            app.PinOffButton_2.Text = 'PinOff';

            % Create PinOnButton_3
            app.PinOnButton_3 = uibutton(app.UIFigure, 'push');
            app.PinOnButton_3.Position = [107 171 165 62];
            app.PinOnButton_3.Text = 'PinOn';

            % Create PinOffButton_3
            app.PinOffButton_3 = uibutton(app.UIFigure, 'push');
            app.PinOffButton_3.Position = [370 171 165 62];
            app.PinOffButton_3.Text = 'PinOff';

            % Create PinOnButton_4
            app.PinOnButton_4 = uibutton(app.UIFigure, 'push');
            app.PinOnButton_4.Position = [107 94 165 62];
            app.PinOnButton_4.Text = 'PinOn';

            % Create PinOffButton_4
            app.PinOffButton_4 = uibutton(app.UIFigure, 'push');
            app.PinOffButton_4.Position = [370 94 165 62];
            app.PinOffButton_4.Text = 'PinOff';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = comunArdTest

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end