function OutputFunc_V3(Arduino,Pin,Alarm1,Alarm2,tWake,times)
    %% Stop logging the sleep cycle
    !taskkill -f -im Gobetwino.exe
    
    %% Alarm sounds
    [y1,Fs1] = audioread(Alarm1);                               % Smart alarm translated into sound samples y1 and sample frequency Fs1
    [y2,Fs2] = audioread(Alarm2);                               % Standard alarm translated into sound samples y2 and sample frequency Fs2
    
    %% Maximal sound and light intensity boundaries
    if exist('Feedback.mat','file') == 0
        Smax = [];                                              % Array containing the values of Smax
        SFb = [];                                               % Array containing the feedback on Smax
        Lmax = [];                                              % Array containing the values of Lmax
        LFb = [];                                               % Array containing the feedback on Lmax
        save('Feedback.mat','Smax','SFb','Lmax','LFb','-v7.3'); % Creates feedback matrix
        Fb = matfile('Feedback.mat','Writable',true);           % Loads feedback matrix
        Smax = 3;                                               % Maximal sound amplitude
        Lmax = 3;                                               % Maximal light voltage
    else
        Fb = matfile('Feedback.mat','Writable',true);           % Loads feedback matrix
        Smin = 1;                                               % This variable is to make sure that the alarm always makes an audible sound
        Smax = mean(Fb.Smax+Fb.SFb);                            % New maximal volume is determined by looking at the total feedback
        if Smax < Smin
            Smax = Smin;                                        % Maximal volume needs to have a certain level so that the sound is still audible
            disp('Notice: minimal sound level reached');        % The user is notified of the corrected value for Smax
        elseif Smax > 5
            Smax = 5;                                           % Maximal volume can't be higher than 5
            disp('Notice: maximal sound level reached');        % The user is notified of the corrected value for Smax
        end
        Lmin = 1;                                               % This variable is to make sure that the light is always visible
        Lmax = mean(Fb.Lmax+Fb.LFb);                            % New maximal brightness is determined by looking at the total feedback
        if Lmax < Lmin
            Lmax = Lmin;                                        % Maximal brightness needs to have a certain level so that the light is still visible
            disp('Notice: minimal light level reached');        % The user is notified of the corrected value for Lmax
        elseif Lmax > 5
            Lmax = 5;                                           % Maximal voltage on an Arduino pin is 5 V
            disp('Notice: maximal light level reached');        % The user is notified of the corrected value for Lmax
        end
    end
    
    %% Smart alarm properties (Alarm1)
    Interval = tWake - clock*times;                             % Time between the start of the script and the moment the user needs to wake up
    BuildUp = [0 0 0 0 5 0]*times;                              % Time interval in which the sound and light increase in intensity
    y1max = Fs1*Interval;                                       % Number of sound samples to be used during the 'wake up interval'
    y1BUp = Fs1*BuildUp;                                        % Number of sound samples to be used during the build up of the sound and light intensity
    [Nrow1,Ncol1] = size(y1);                                   % Number of rows (number of sound samples) and collumns (number of audio channels) in y1
    if y1BUp > Nrow1
        BuildUp = Nrow1/Fs1;                                    % The 'build up' must happen within the duration of the audio file
        y1BUp = Nrow1;
    end
    if Interval > BuildUp
        dS = Smax/y1BUp;                                        % Step size of the 'sound multiplication factor array'
        S = dS:dS:Smax;                                         % Sound multiplication factor array: determines the maximal volume of the sound for each sample during the 'build up'
        S2 = repmat(S,Ncol1,1);                                 % All collumns of y1 need to be scaled
        [y1_1,y1_2] = deal(Smax*y1);                            % The sound samples of y1 are scaled using Smax
        y1_2(1:y1BUp,:) = S2'.*y1(1:y1BUp,:);                   % The samples belonging to the 'build up' need to increase in amplitude
        n1 = floor(y1max/Nrow1);                                % Number of times the sound file needs to be repeated at most
    else
        BuildUp = Interval;                                     % The 'build up' must be over by the end of Interval
        dS = Smax/y1max;                                        % Step size of the 'sound multiplication factor array'
        S = dS:dS:Smax;                                         % Sound multiplication factor array: makes sure the smart alarm gradually increases in volume during the 'build up'
        S2 = repmat(S,Ncol1,1);                                 % All collumns of y1 need to be scaled
        y1_2 = S2'.*y1(1:y1max,:);                              % The samples for the 'build up' are created
    end

    %% Smart light properties
    dL = Lmax/ceil(BuildUp);                                    % Step size of the 'light multiplication factor array'
    L = dL:dL:Lmax;                                             % Light multiplication factor array: makes sure the lights gradually increase in brightness

    %% Play smart alarm
    y1Play1 = audioplayer(y1_2,Fs1);                            % Convert the sound file to an audioplayer (works faster than simply using the sound() function)
    play(y1Play1);                                              % Play the smart alarm sound which gradually increases in volume due to S
    for t = 1:ceil(BuildUp)
        writePWMVoltage(Arduino,Pin,(L(t)^2)/Lmax);             % Gradually increases the voltage on the pin that's connected to the lights
        k = getkeywait(1);                                      % Voltage is increased every second
        if k > -1
            break;                                              % If a button is pressed, the smart alarm needs to stop
        end
    end
    if Interval > BuildUp && k == -1
        tAlarm1 = Nrow1/Fs1;                                    % Duration of the smart alarm sound file
        if tAlarm1 > ceil(BuildUp)
            k = getkeywait(ceil(tAlarm1-BuildUp));              % If the sound file hasn't ended yet after the 'build up', it needs to be finished
        end
        stop(y1Play1);                                          % Stop the smart alarm sound if it hasn't stopped yet
        if k == -1
            y1Play2 = audioplayer(y1_1,Fs1);                    % Convert the sound file to an audioplayer
            for i = 1:n1
                play(y1Play2);                                  % Repeat the smart alarm
                k = getkeywait(ceil(tAlarm1));                  % Wait for the user to press any key
                stop(y1Play2);                                  % Stop the sound if the user has pressed a key or if the audio file has ended
                if k > -1
                    break;                                      % If the user has pressed a key, the smart alarm needs to stop
                end
            end
        end
    else
        stop(y1Play1);                                          % Stop the smart alarm sound if it hasn't stopped yet
    end
    
    %% Play standard alarm (Alarm2)
    if k == -1                                                  % If no key has been pressed, the user isn't awake yet, so the standard alarm jumps into action
        n2 = 10;                                                % Number of times the standard alarm needs to be played at most
        y2_1 = Smax*y2;                                         % The volume of the alarm sound is scaled using Smax
        y2_2 = repmat(y2_1,n2,1);                               % To make the alarm loop, it's simply copied after eachother a couple of times
        Nrow2 = size(y2,1);                                     % Number of rows (number of sound samples) in y2
        sound(y2_2,Fs2);                                        % Play the standard alarm
        writePWMVoltage(Arduino,Pin,Lmax);                      % Set the lights to maximal brightness
        getkeywait(ceil(n2*Nrow2/Fs2));                         % Wait until the user is awake and presses a button
        clear sound;                                            % Stop the standard alarm sound
    end
    writePWMVoltage(Arduino,Pin,0);                             % Shut the lights
    
    %% Feedback
    Fb.Smax(1,end+1) = Smax;                                    % Give feedback about this volume setting
    Fb.Lmax(1,end+1) = Lmax;                                    % Give feedback about this brightness setting
    Fb.SFb(1,end+1) = 3 - input('Rate your sound experience:\n 1 = Too soft\n 2 = Soft\n 3 = OK\n 4 = Loud\n 5 = Too loud\n');
    Fb.LFb(1,end+1) = 3 - input('Rate your light experience:\n 1 = Too dim\n 2 = Dim\n 3 = OK\n 4 = Bright\n 5 = Too bright\n');
    Fbmax = 5;                                                  % Maximal number of rows of the feedback matrix
    if size(Fb.Smax,2) > Fbmax;                                 % Feedback matrix can't have more than Fbmax collumns
        Fb.Smax = Fb.Smax(1,2:end);                             % Delete first element
        Fb.Lmax = Fb.Lmax(1,2:end);                             % Delete first element
        Fb.SFb = Fb.SFb(1,2:end);                               % Delete first element
        Fb.LFb = Fb.LFb(1,2:end);                               % Delete first element
    end
end