How can i implement a timed counter in app designer
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Keenan Jogiah
le 21 Déc 2021
Commenté : Keenan Jogiah
le 21 Déc 2021
I really need to make use of a counter that will increase every 0.25 seconds in app designer ,I've used the timer function in a matlab script but I'm not sure how to go about implementing this in app designer, i want the count variable to increase after every 25 milliseconds as long as the toggle switch is in a certain position . Please help from the beginning, im not familiar with app designer whatsoever
0 commentaires
Réponse acceptée
Geoff Hayes
le 21 Déc 2021
@Keenan Jogiah - you could create a timer object within the app that you would then start and stop based on the toggle. In this example, I'm assuming that the toggle is a checkbox - when checked, the timer will start and update the text area with a value that will increase by one over time. When the checkbox is unchecked, the timer will be stopped. I needed to add the following code to do this
properties (Access = private)
mTimer % timer
mCounter; % integer counter
end
which are the data members for the timer object and counter. The callback for the checkbox does "all" of the work
% Callbacks that handle component events
methods (Access = private)
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
value = app.CheckBox.Value;
if value == 1
% checkbox is checked so reset counter, create and start
% timer
app.mCounter = 0;
app.mTimer = timer('TimerFcn', @timerCallback, 'ExecutionMode', 'FixedRate', 'Period', 0.25);
start(app.mTimer);
else
% checkbox is unchecked so stop timer
stop(app.mTimer);
end
% this is the callback for the timer
function timerCallback(~, ~)
% update the text area and increment the timer
app.TextArea.Value = num2str(app.mCounter);
app.mCounter = app.mCounter + 1;
end
end
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!