sumplight off time = sumplight on time + sumplight duration
if sumplight off time > 1440 then sumplight off time = sumplight off time - 1440 and set next day flag
...
then we have a flag (slf) that is 1 when sumplight is on else 0 and a next day flag (ndf) that is set to 1 when offtime overflows else 0
the ndf flag is cleared at midnight in you time routine , the chklight sub is called once every minute
chklight: check light subroutine
if slf=0 then
if count >= on time then
slf=1
offtime = count+duration
ndf=0
if offtime >1440 then
offtime=offtime -1440
ndf=1
endif
turn on light
endif
else
if ndf=1 then return
if count >= offtime then
slf=0
turn off light
endif
endif
return
return
Bookmarks