MATLAB: Use a button to increase a value in simulink each time it is pressed
simulink
I am trying to simulate shifting gears in simulink. I want to increase a constant each time it is pressed. I have 6 dashboard lamps that I am going to use as gear indicators.
Thank you.
Best Answer
Alright most people probably already know how to do this but I finally figured it out. It is just done through a triggered subsystem that uses a matlab function. In my case, a button was pressed that made a constant block go from low to high (trigger). Then another constant block is fed into the matlab function that uses get_param(constant2) and set_param(constant2+1) to shift the constant block up one value.
Then you just connect your lamp to the constant block that is changing and you have your solution.
Biggest things learned: constant blocks need to be stored as a string so str2num and num2str must be used in parameter setting; trigger subsystem just acts once per activation! Also you can ask and answer your own questions in MATLAB forums!
Best Answer