Week program


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

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

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;

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

Would love to see how others would do it.


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):

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 );

digital_point = 0;
to: TurnOff( digital_point );

but I’m just putting ruffles on it now…