Daily timer
GrantmcF
Posts: 30
I'm trying to schedule a cooler to come on and turn off at a set time of day. My code keeps blowing by my if statement and going to the else and turning it off. Can anyone give me a hint or point me at a good sample of code? The week day or weekend selection works ok. This is the section of code where I'm having the problem.
Pub Timer Time_total := ((hour*60)+minute) Wkdystrt_total := ((Wkdy_hrstart*60)+Wkdy_minstart) Wkdystp_total := ((Wkdy_hrstop*60)+Wkdy_minstop) Wkndstrt_total := ((Wknd_hrstart*60)+Wknd_minstart) Wkndstp_total := ((Wknd_hrstop*60)+Wknd_minstop) case dow 1,7: Wknd_Timer 2,3,4,5,6: Wkdy_Timer Pub Wkdy_Timer WkdyT_status:= 1 If (Time_total => Wkdystrt_total) 'and (Time_total <= Wkdystp_total) Control_logic '(go to control logic) Else cogstop(Relay_cog~ -1) Relay_cog := cognew( Cooler_off,@ Relay_Stack)+1 Loop Pub Wknd_Timer WkndT_status:= 1 If (Time_total => Wkndstrt_total) and (Time_total <= Wkndstp_total) Control_logic '(go to control logic) Else cogstop(Relay_cog~ -1) Relay_cog := cognew( Cooler_off,@ Relay_Stack)+1 Loop
Comments
Should be:
That's why nowdays I never use the "less/greater than or equal to" operator, I just use the "less/greater than" operator. It makes it easier on my head, and I don't have to worry about it.
If you must think about it, then the easiest way (for me) is to remember things like "+=" and "-=", where the operator is on the left side, and the assignment is on the right.
Anyway, it looks like you are stopping and starting the Wet/Dry_high/low cog every 9 seconds (every time through the loop)? Why the constant restarting and starting? There is also a bug: the first time through the loop, when Relay_cog = 0, it tries to stop cog -1.
For your stop time before start time issue, you would need to add another case (or condition) to your if statements. Something like: