can someone give me the matlab function code for setting the time for a certain system to turn on?
3 views (last 30 days)
Show older comments
setting the time to automatically turn on the light, for example, the light will turn on from 7am to 12 am, and 1pm to 5pm every monday, wednesday and friday. then 8am to 11am, and 12nn to 4pm every tuesday, thursday and saturday, thanks
1 Comment
Answers (3)
Image Analyst
on 8 Feb 2016
You can put
theDateTime = datestr(now)
in a loop and then parse the string for whatever conditions you want. You might also set up a time to get that string if you want to do it with that approach.
3 Comments
Image Analyst
on 9 Feb 2016
I think that would be a perfect learning opportunity for you. You got to learn sometime because you can't go around asking other people to write code for you, so what better time to learn than with this simple example?
Walter Roberson
on 9 Feb 2016
No, in order to give you that code we would need documentation on the mechanisms your device requires to turn it on or off.
Perhaps you should make your requirement clearer. Do you need a function that, when run, tells you whether the light should be on or off at the current time? (If so, how would you test it for other times?)
16 Comments
Jan
on 20 Feb 2016
Edited: Jan
on 20 Feb 2016
This seems a job for a timer:
function SetTimer(Date, Func, Args)
% Date as DATESTR: "2016-Mar-01 12:23:15'
% Func: Function handle to the function, which is called at teh specified time
% Arguments for the called function as {1 x N} cell
Delay = round((datenum(Date) - now) * 86400); % in seconds
TimerH = timer('ExecutionMode', 'singleShot', ...
'StartDelay', Delay, ...
'TimerFcn', cat(2, {Func}, Args));
start(TimerH);
end
Now the main program and a function for switching:
function Main
Time1 = datestr(now + 10 / 86400, 0); % In 10 seconds
Time2 = datestr(now + 12 / 86400, 0) % In 12 seconds
SetTimer(Time1, @TheSwitcher, {'on'});
SetTimer(Time2, @TheSwitcher, {'off'});
end
function TheSwitcher(TimerH, EventData, Arg)
% Here the code appears to perform the wanted operation.
disp(Arg);
end
9 Comments
Calvin Page
on 13 Mar 2017
hey. evrenl..have you solved your problem about your time scheduling.we might have the same problem :)..i might be searching for about 4 weeks just to get this topic. :( can i have some of your data that you have gathered about the time scheduler..ill be happy to :) thank you in advance :) God bless..
Calvin Page
on 13 Mar 2017
Edited: Walter Roberson
on 13 Mar 2017
and by the way can i also see your Gui that you have made :) just to have some ideas.. thanks..
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!