classdef App_Diode_temp < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure            matlab.ui.Figure
        TextArea            matlab.ui.control.TextArea
        FermerButton        matlab.ui.control.Button
        TS2                 matlab.ui.control.DropDown
        TensionseuilVLabel  matlab.ui.control.Label
        TracerButton        matlab.ui.control.Button
        UIAxes              matlab.ui.control.UIAxes
    end

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

        % Button pushed function: FermerButton
        function FermerButtonPushed(app, event)
            closereq
        end

        % Button pushed function: TracerButton
        function TracerButtonPushed(app, event)
            V0=0.026; 
            n=1;
            %I0=1e-8;
            Vseuil=str2num(app.TS2.Value);
            if Vseuil==0.3
                I0=4.7*1e-7;
            elseif Vseuil==0.4
                I0=1e-8;
            elseif Vseuil==0.5
                I0=2.1*1e-10;
            elseif Vseuil==0.6
                I0=4.5*1e-12;
            elseif Vseuil==0.7
                I0=9.7*1e-14;
            elseif Vseuil==0.8
                I0=2.1*1e-15;
            else
                I0=2.1*1e-10;
            end
            Vj=linspace(0,Vseuil,100);
            I=I0*(exp(Vj/(n*V0))-1);
            plot(app.UIAxes,Vj,I,'r')
            title(app.UIAxes,'Caractéristique d''une diode')
            xlabel(app.UIAxes,'Tension (V)')
            ylabel(app.UIAxes,'Courant (A)')
            grid(app.UIAxes,'on')
        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 667 480];
            app.UIFigure.Name = 'UI Figure';

            % Create UIAxes
            app.UIAxes = uiaxes(app.UIFigure);
            title(app.UIAxes, 'Caractéristique d''une diode')
            xlabel(app.UIAxes, 'X')
            ylabel(app.UIAxes, 'Y')
            app.UIAxes.GridAlpha = 0.15;
            app.UIAxes.MinorGridAlpha = 0.25;
            app.UIAxes.Position = [226 44 423 399];

            % Create TracerButton
            app.TracerButton = uibutton(app.UIFigure, 'push');
            app.TracerButton.ButtonPushedFcn = createCallbackFcn(app, @TracerButtonPushed, true);
            app.TracerButton.BackgroundColor = [0.502 0.502 0.702];
            app.TracerButton.FontSize = 16;
            app.TracerButton.FontWeight = 'bold';
            app.TracerButton.Position = [71 255 129 30];
            app.TracerButton.Text = 'Tracer';

            % Create TensionseuilVLabel
            app.TensionseuilVLabel = uilabel(app.UIFigure);
            app.TensionseuilVLabel.BackgroundColor = [0.9294 0.6902 0.1294];
            app.TensionseuilVLabel.HorizontalAlignment = 'right';
            app.TensionseuilVLabel.VerticalAlignment = 'top';
            app.TensionseuilVLabel.Position = [81 365 96 15];
            app.TensionseuilVLabel.Text = 'Tension seuil (V)';

            % Create TS2
            app.TS2 = uidropdown(app.UIFigure);
            app.TS2.Items = {'0.3', '0.4', '0.5', '0.6', '0.7', '0.8'};
            app.TS2.BackgroundColor = [0.4706 0.6706 0.1882];
            app.TS2.Position = [81 333 111 22];
            app.TS2.Value = '0.3';

            % Create FermerButton
            app.FermerButton = uibutton(app.UIFigure, 'push');
            app.FermerButton.ButtonPushedFcn = createCallbackFcn(app, @FermerButtonPushed, true);
            app.FermerButton.BackgroundColor = [1 0.102 0];
            app.FermerButton.FontWeight = 'bold';
            app.FermerButton.Position = [79 77 113 25];
            app.FermerButton.Text = 'Fermer';

            % Create TextArea
            app.TextArea = uitextarea(app.UIFigure);
            app.TextArea.FontName = 'Courier';
            app.TextArea.FontSize = 14;
            app.TextArea.FontWeight = 'bold';
            app.TextArea.BackgroundColor = [0.8 0.8 0.8];
            app.TextArea.Position = [25.671875 408 152 60];
            app.TextArea.Value = {'IUT de l''Indre'; 'Département GEII'; 'Enseignant JMR'};

            % 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 = App_Diode_temp

            % 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