DS3231 track days

I am using a DS3231 RTC to keep track of time and days for a project of mine and my incredibly limited experience with Arduino has got me stumped. I have defined the days as following:

//Define days of the week
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

I believe the array values are Sun = 0 thru Sat = 6

Later in my code I try to use this for an if statement as follows in hopes that if these criteria are true then I can power up my output. However, I have created a false condition when I tested the system on Sunday (0) when the last part of the if statement is not true and I was still able to energize my output when I should not have been able to I would appreciate any help and direction someone could provide:


DateTime now = rtc.now();

if ((now.hour() >= 7) && (now.hour() <= 16) && (now.day() != 0 || 6);
  {
  sys_operate = true;
  }
  else
  {
  sys_operate = false:
  }
}

this part is wrong,

(now.day()!=0 && now.day()!=6)

Ahh, I shouldn't have combined them they way I did. I will give that a try! Thank you!

Upon further looking, when I serial print the dat it gives me "10" instead of 1 for Monday. Why is it giving me a value outside of the 7 identified days? What am I missing, does it have something to do with the [12] after the [7] in the initial message?

Could it be that "now.day()" is the date, like 10 of April ?
Maybe try "now.dayOfTheWeek()".

That is what I am thinking, I really need to be able to identify days of the week and not days of the month instead. I want this portion of my program to be true for Mon - Fri
7 am to 4 pm or thus the 7 - 16 shown in the initial code.

I have edited post #5 (too late :confused:)

That is what the problem was! I also had it spelled "daysOfTheWeek" once I removed the "s" from days that and adjusting it in the if statement fixed the issue!
Thank you so much!!!!

You're welcome.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.