Week program


#1

Hello,

i need some help with switching on and off of a digital point.

i want to switch it on every workday including saturday at 6.45 and switch it of every night at 19:00 hour.
and it should not turn on on sunday.

can someone help me.

Greets Ruben


#2

Hi RSmits,

Welcome to the forums.

Im a hack programmer, and I have not tested this code, but here is how I would do it;


//GetDayOfWeek(); Sun=0, Mon=1, Tue=2, Wed=3, Thur=4, Fri=5, Sat=6
//GetSecondsSinceMidnight(); 

day_of_week = GetDayOfWeek();
seconds_since_midnight = GetSecondsSinceMidnight();
if ((day_of_week > 0) and (day_of_week <= 5) and (seconds_since_midnight == 24300))
  then digital_point = 1;
endif

if (seconds_since_midnight == 68400)
  then digital_point = 0;
endif


Would love to see how others would do it.

Ben.


#3

Hi Schedule Fans,

There’s also this fancier/more complicated scheduler example that might be helpful (be sure to check out the tech note too):
http://www.opto22.com/site/downloads/dl_drilldown.aspx?aid=3961

I just adjusted a couple of things in Ben’s example above (like checking for Sunday).
On those seconds_since_midnight values to compare (at 6:45 & 19:00), I’d be inclined to make those (persistent) variables instead of hard-coded so you could adjust them without changing the program.

Also note that this logic assumes we’re looping around checking all this at least every second (every 500 milliseconds might be better). Otherwise we might miss those specific values!

I might also change:
digital_point = 1;
to: TurnOn( digital_point );

and
digital_point = 0;
to: TurnOff( digital_point );

but I’m just putting ruffles on it now…
:slight_smile:

-OptoMary