function Switch_output = Switching_logic_tank_2(LC_pri, LC_sec, time)
global Switch_tank_2;
% Switch_tank_2 = 1 --> LC_pri is active
% Switch_tank_2 = 0 --> LC_sec is active
global switching_delay_2
 if LC_pri ~= 0
    if Switch_tank_2 == 1 % Checking if F2 controller is active
        if time >= switching_delay_2
        Switch_tank_2 = 0; % Makng F1 active
        switching_delay_2 = time + 0.1; % Switching cannot occur more than every 6 seconds = 0.1 minutes
        end
    end
 end
if LC_sec ~= 0
   if Switch_tank_2 == 0 % Checking if F1 controller is active
      if time >= switching_delay_2
        Switch_tank_2 = 1; % Makng F2 active
        switching_delay_2 = time + 0.1; % Switching cannot occur more than every 6 seconds = 0.1 minutes
      end
   end
end
Switch_output = Switch_tank_2;
end