-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSetTimer.m
47 lines (39 loc) · 1.34 KB
/
SetTimer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function SetTimer()
% this funcrtion is used for set timer to initial value
%
% elapsed time ( from first click)
global timeElapsed;
% time text handler
global timeControl;
% a object for timer
global timerobj;
% set time to 0 at the beginning
timeElapsed = 0;
timeControl = uicontrol('Units', 'normalized', 'Style', 'text');
set(timeControl, 'string', "000", 'FontSize', 13,'backgroundcol',[1 .4 .4],'FontWeight','bold');
set(timeControl, 'Position', [0.65,0.87, 0.3, 0.08]);
% initial timer obj
timerobj = timer('TimerFcn',@(s,e)UpdateTime(), ...
'ExecutionMode','FixedRate', ...
'Period',1, ...
'StartDelay',1);
end
function UpdateTimeDisplay()
global timeElapsed;
global timeControl;
% Get current time elapsed
sec = timeElapsed;
% show curretn time
secstr = sprintf('%03d',sec);
set(timeControl, 'string', secstr, 'FontSize', 13,'backgroundcol',[1 .4 .4],'FontWeight','bold');
set(timeControl, 'Position', [0.65,0.87, 0.3, 0.08]);
end
function UpdateTime()
global timeElapsed;
% Increment time counter
timeElapsed = timeElapsed + 1;
% Update time display
if (timeElapsed <= 999)
UpdateTimeDisplay();
end
end