How can i implement a timed counter in app designer
36 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Geoff Hayes
2021 年 12 月 21 日
@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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Create Custom UI Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!