필터 지우기
필터 지우기

How can i implement a timed counter in app designer

조회 수: 28 (최근 30일)
Keenan Jogiah
Keenan Jogiah 2021년 12월 21일
댓글: Keenan Jogiah 2021년 12월 21일
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

채택된 답변

Geoff Hayes
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
  댓글 수: 1
Keenan Jogiah
Keenan Jogiah 2021년 12월 21일
Thank you so much, I was pretty lost with the app designer syntax

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by