PDA

View Full Version : Some advice on this simple "lived in look" code...


mattyb
05 Dec 07, 03:51 PM
G'day

I'm looking for a bit of a sanity check on the code below and hope someone will be kind enough to offer their thoughts.

This is meant to be a very simple "lived in look" but the client reports that whenever they, or their cleaners, arrive home after being away that "Holiday Scene 1" is always set. Apparently the code that sets the following scenes to turn all the lights OFF never gets called.

I have tested the code just on PICED with shorter random times and have found that sometimes the code gets to "Holiday Scene 2" and has never got to "Holiday Scene 3".

Any thoughts on why it's not working properly or ways to improve it would be appreciated.

Thanks

Matt


{Initialise Random Times Each Day}
if (Time = "2:00:00 AM") then
begin
RandomTime2 := random("03:00:00");
RandomTime3 := random("01:05:00");
end;



once (time > (sunset)) then
begin
if (GetEnableState("HOLIDAY MODE") = ON) then
begin
SetScene("Holiday Scene 1");
{Evening}
TimerStart(1);
end;
end;

once (TimerTime(1) > RandomTime2) then
begin
SetScene("Holiday Scene 2");
{Bedtime}
TimerStop(1);
TimerStart(2);
end;

once (TimerTime(2) > RandomTime3) then
begin
SetScene("Holiday Scene 3");
{Goodnight}
TimerStop(2);
end;

lcrowhurst
05 Dec 07, 11:00 PM
I tested it in homegate with shorter times , and it worked.

Maybe the random time is some times set to 0 so the code doesnt see a (once ) change. Try adding a few minutes to the random time.


eg
RandomTime2 := random("03:00:10")+ 120;

mattyb
06 Dec 07, 07:48 AM
Thanks Laurence

While testing out your suggestion I realised another of my modules was using a whole bunch of timers and I had two pieces of code doing things based on the same timer...:o

I had been conscientious when I began coding and done things like

GARAGE_PIR_TIMER=1;

...

TimerStart(GARAGE_PIR_TIMER);


but then fell into slackness and just threw around things like TimerStart(1)...

Anyway, another lesson learned...thanks for your help!