-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI_clock.m
55 lines (52 loc) · 2.01 KB
/
GUI_clock.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
48
49
50
51
52
53
54
55
function [] = GUI_clock()
% Demonstrate how to have a running clock in a GUI.
% Creates a small little GUI which displays the correct time and is updated
% every minute according to the system clock.
%
% Author: Matt Fig
% Date: 1/15/2010
S.fh = figure('units','pixels',...
'position',[300 300 180 50],...
'menubar','none',...
'name','GUI_clock',...
'numbertitle','off',...
'resize','off');
S.tx = uicontrol('style','text',...
'unit','pix',...
'position',[35 10 110 30],...
'string',datestr(now,16),...
'backgroundc',get(S.fh,'color'),...
'fontsize',18,...
'fontweight','bold',...
'foregroundcolor',[.9 .1 .1]);
STRT = 60 - str2double(datestr(now,'ss')); % So we can update every minute.
tmr = timer('Name','Reminder',...
'Period',60,... % Update the time every 60 seconds.
'StartDelay',STRT,... % In seconds.
'TasksToExecute',inf,... % number of times to update
'ExecutionMode','fixedSpacing',...
'TimerFcn',{@updater});
start(tmr); % Start the timer object.
set(S.fh,'deletefcn',{@deleter}) % Kill timer if fig is closed.
function [] = updater(varargin)
% timerfcn for the timer. If figure is deleted, so is timer.
% I use a try-catch here because timers are finicky in my
% experience.
try
set(S.tx,'string',datestr(now,16))
if ~str2double(datestr(now,'MM'))
X = load('gong');
player = audioplayer(X.y, X.Fs);
play(player) % Gong at the top of the hour.
end
clear y Fs player
catch
delete(S.fh) % Close it all down.
end
end
function [] = deleter(varargin)
% If figure is deleted, so is timer.
stop(tmr);
delete(tmr);
end
end