Hi Kizito,
To control a switch in Simulink from an App Designer UI and ensure it toggles correctly throughout the simulation, follow these steps:
Check Simulation Setup: Ensure the Simulink model allows parameter changes during the simulation, preferably in 'Normal' mode, and that your switch logic is part of a discrete system for continuous checking.
Implementing a Toggle Button:
- Add a private property, ToggleState, to track the switch state.
- In the button push function, toggle this state between true and false.
- Update the Simulink switch parameter ('sw') based on the ToggleState.
properties (Access = private)
ToggleState = false; % Initialize as off
end
function ToggleSwitchButtonPushed(app)
app.ToggleState = ~app.ToggleState; % Toggle the state
set_param('ChargingProcess/ChargeMyCar', 'sw', app.ToggleState ? '1' : '0'); % Update Simulink switch
end
Ensure Correct Configuration:
- Verify the simulation mode supports real-time updates.
- Confirm the path and parameter name used in set_param calls are correct.