function ModeSelectionCallback(source,callbackdata)

global BridgeDC LoadDC canch1 mode;
global m1_SpecificPower;
global TargetVoltage;
global ScaleFactor RetractFactor;
global m2_LoadDCSlider_h m2_BridgeDCSlider_h m2_LoadDCtxt_h m2_BridgeDCtxt_h;
global m1_TargetVoltageSlider_h m1_SpecificPowerSlider_h m1_TargetVoltagetxt_h m1_SpecificPowertxt_h;
global m0_ScaleFactorSlider_h m0_RetractFactorSlider_h m0_ScaleFactortxt_h m0_RetractFactortxt_h;

switch callbackdata.OldValue.String
    case ('Mode 2')
        BridgeDC = 1.0;  LoadDC = 0.0;  %Set Defaults
        m2_BridgeDCSlider_h.Value = BridgeDC;
        m2_LoadDCSlider_h.Value = LoadDC;
        m2_BridgeDCSlider_h.Visible = 'off';
        m2_BridgeDCtxt_h.Visible = 'off';
        m2_LoadDCSlider_h.Visible = 'off';
        m2_LoadDCtxt_h.Visible = 'off';
    case ('Mode 1')
        m1_TargetVoltageSlider_h.Visible = 'off';
        m1_TargetVoltagetxt_h.Visible = 'off';
        m1_SpecificPowerSlider_h.Visible = 'off';
        m1_SpecificPowertxt_h.Visible = 'off';
    case ('Mode 0')
        ScaleFactor = 0.8;
        RetractFactor = 0.6;
        m0_ScaleFactorSlider_h.Value = m1_SpecificPower;
        m0_RetractFactorSlider_h.Value = RetractFactor;
        m0_ScaleFactorSlider_h.Visible = 'off';
        m0_RetractFactorSlider_h.Visible = 'off';
        m0_ScaleFactortxt_h.Visible = 'off';
        m0_RetractFactortxt_h.Visible = 'off';
        m1_TargetVoltagetxt_h.Visible = 'off';
end

switch callbackdata.NewValue.String
    case ('Mode 2')
        mode = 2;
        BridgeDC = 1.0;  LoadDC = 0.0;  %Set Defaults
        m2_BridgeDCSlider_h.Value = BridgeDC;
        m2_LoadDCSlider_h.Value = LoadDC;
        m2_BridgeDCSlider_h.Visible = 'on';
        m2_LoadDCSlider_h.Visible = 'on';
        m2_BridgeDCtxt_h.Visible = 'on';
        m2_LoadDCtxt_h.Visible = 'on';
        SetMode2(canch1, BridgeDC, LoadDC);
    case ('Mode 1')
        mode = 1;   
        m1_SpecificPower = .1;
        TargetVoltage = 100;
        m1_TargetVoltageSlider_h.Value = TargetVoltage;
        m1_SpecificPowerSlider_h.Value = m1_SpecificPower;
        m1_TargetVoltageSlider_h.Visible = 'on';
        m1_TargetVoltagetxt_h.Visible = 'on';
        m1_SpecificPowerSlider_h.Visible = 'on';
        m1_SpecificPowertxt_h.Visible = 'on';
        SetMode1(canch1, TargetVoltage, m1_SpecificPower);
    case ('Mode 0')
        mode = 0;
        ScaleFactor = 0.8;
        RetractFactor = 0.6;
        m0_ScaleFactorSlider_h.Value = ScaleFactor;
        m0_RetractFactorSlider_h.Value = RetractFactor;
        m0_ScaleFactorSlider_h.Visible = 'on';
        m0_RetractFactorSlider_h.Visible = 'on';
        m0_ScaleFactortxt_h.Visible = 'on';
        m0_RetractFactortxt_h.Visible = 'on';
        m1_TargetVoltagetxt_h.Visible = 'on';
        m1_TargetVoltageSlider_h.Visible = 'on';
        SetMode0(canch1, ScaleFactor, RetractFactor);

end
display(['Previous: ' callbackdata.OldValue.String]);
display(['Current: ' callbackdata.NewValue.String]);
display('------------------');
end