Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
schedule doesn't work
#1
Sad 
I'm trying to set up a relay on/off schedule. The problem is that all days work correctly except Sunday; on Sunday the schedule does not work at all.

here is my code:
Code:
byte stringToByte(const char* str)
{
    byte data = 0;
    for (uint8_t i = 0; i < 7; i++)
    {
        if (str[i] == '1')
        {
            bitSet(data, i);
        }
        if (str[i] == '0')
        {
            bitClear(data, i);
        }
    }
    return data;
}
Reply
#2
(04-16-2024, 06:29 PM)dimentiy89 Wrote: I'm trying to set up a relay on/off schedule. The problem is that all days work correctly except Sunday; on Sunday the schedule does not work at all.

here is my code:
Code:
byte stringToByte(const char* str)
{
    byte data = 0;
    for (uint8_t i = 0; i < 7; i++)
    {
        if (str[i] == '1')
        {
            bitSet(data, i);
        }
        if (str[i] == '0')
        {
            bitClear(data, i);
        }
    }
    return data;
}

I'll answer my own question.
It turns out the week starts on Monday and not on Sunday.
Monday = 0
Sunday = 6
solved it this way:

Code:
if (dayOfWeek > 0)
{
    dayOfWeek -= 1; //fix monday-saturday
}
else
{
    dayOfWeek = 6; //fix sunday
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)