Here's a few tips...
Since you're not really using the functions 'decrease', 'increasemin', and 'increasehour' as functions
I'd change them to 'subs' so that it's a little clearer how you're using them...
- Code: Select all
sub decrease(byref val as byte)
if (val > 0) then
val = val - 1
endif
delayms(100)
end sub
// increase minutes... wrap 59 -> 0
sub increasemin(byref val as byte)
if (val < 59) then
val = val + 1
else
val = 0
end if
delayms(100)
end sub
// increase hours... wrap 23 -> 0
sub increasehour(byref val as byte)
if (val < 23) then
val = val + 1
else
val = 0
end if
delayms(100)
end sub
Now, for the start and stop times... it can be tricky working in hours, minutes (and seconds).
Here's what the code currently looks like...
- Code: Select all
Dim Starthour As Byte = 8
Dim Stophour As Byte = 17
Dim Startmin As Byte = 0
Dim Stopmin As Byte = 0
if (time.hour >= Starthour) and (time.hour < Stophour) then
if (time.minute >= Startmin) and (time.minute < Stopmin) then
Dogm.WriteAt(1,1,Str(Time.Hour, 2),":",Str(Time.Minute,2),":",Str(Time.Second,2)," RUNNING ")
<other code for running interval>
end if
end if
If you look at the 'minutes' comparison, since 'startmin' and 'stopmin' are zero the first part of that test is always true,
while the second part is always false.
When working with time I usually find it easier to convert hours:min:secs to a single value and work in minutes or seconds,
depending on what you're comparing...
- Code: Select all
Dim Starthour As Byte = 8
Dim Stophour As Byte = 17
Dim Startmin As Byte = 0
Dim Stopmin As Byte = 0
Dim CurrentTime, StartTime, StopTime as uInteger // times in minutes
// read time from the rtc
Time = DS1307.ReadTime()
// convert hours:minutes to minutes
CurrentTime = (time.hour * 60) + time.minute
StartTime = (Starthour * 60) + Startmin
StopTime = (Stophour * 60) + Stopmin
if (CurrentTime >= StartTime) and (CurrentTime < StopTime) then
Dogm.WriteAt(1,1,Str(Time.Hour, 2),":",Str(Time.Minute,2),":",Str(Time.Second,2)," RUNNING ")
<other code for running interval>
end if
For example, you could change the 'Waitinterval' routine to use the RTC seconds time instead of using delay calls...
- Code: Select all
sub Waitinterval(waitsecs as uLong)
dim Button as PORTB.1
dim CurTime as uLong // current time, in seconds
dim ExitTime as uLong // exit time, in seconds
dim seconds as byte
// read current time from rtc, convert to seconds and compute exit time
Time = DS1307.ReadTime()
CurTime = (Time.Hour * 60 * 60) + (Time.Minute * 60) + Time.Second
ExitTime = CurTime + waitsecs
// wait until its time to exit
while (CurTime < ExitTime)
Dogm.WriteAt(1,1,Str(Time.Hour, 2),":",Str(Time.Minute,2),":",Str(Time.Second,2)," RUNNING ")
// wait for rtc seconds to change (easier on the LCD display)
seconds = Time.seconds
while (seconds = Time.seconds)
if (button = 0) then // leave if button pressed (PORTB.1 to GND)
Dogm.WriteAt(1,1,Str(Time.Hour, 2),":",Str(Time.Minute,2),":",Str(Time.Second,2)," STOPPED ")
running = false
exit sub
end if
Time = DS1307.ReadTime()
end while
// update current time
CurTime = (Time.Hour * 60 * 60) + (Time.Minute * 60) + Time.Second
end while
end sub
If you do the same sort of thing with the exposure and interval times then it makes it easier to adjust them
and you can more easily account for the exposure by subtracting it from the interval.