How to create an Alarm Clock in MATLAB App Designer in Simple Steps?

Video shows steps by steps instruction to create a Alarm clock in MATLAB’s App designer using command line.

We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com

Source Code:

function AlarmClock()

figH = uifigure(‘Name’, ‘Alarm Clock’);

labelA = uilabel(figH);
labelA.Text = datestr(datetime(‘now’));
labelA.Position = [100 300 400 45];
labelA.FontSize = 30;
labelA.BackgroundColor = ‘white’;
labelA.VerticalAlignment = ‘center’;
labelA.HorizontalAlignment = ‘center’;
labelB = uilabel(figH);
labelB.Text = ‘Current Time:’;
labelB.Position = [100 320 400 45];
labelB.FontSize = 15;
labelC = uilabel(figH);
labelC.Text = ‘Alarm Time:’;
labelC.Position = [100 220 400 45];
labelC.FontSize = 15;

textA = uitextarea(figH);
textA.Value = datestr(datetime(‘now’));
textA.Position = [100 200 400 45];
textA.FontSize = 30;
textA.HorizontalAlignment = ‘center’;

buttonSet = uibutton(figH);
buttonSet.Text = ‘SET ALARM’;
buttonSet.FontSize = 25;
buttonSet.Position = [175 100 200 40];
buttonSet.ButtonPushedFcn = @(buttonSet, event) setAlarm(labelA, textA, figH);

end

function setAlarm(labelA, textA, figH)

alarmTime = datevec(textA.Value{1});

if(etime(alarmTime,clock) < 0)
labelD = uilabel(figH);
labelD.Text = ‘Alarm Time Passed!’;
labelD.Position = [100 20 400 45];
labelD.FontSize = 20;
labelD.FontColor = ‘red’;
return;
end

while(etime(alarmTime,clock) > 0.5)
labelA.Text = datestr(datetime(‘now’));
end

y = audioread(‘beep.mp3’);
sound(y);
end

Leave a Reply

%d bloggers like this: