I am controlling some relays based in Minutes Since Midnight (MSM)
if (msmNow >= msmStart && msmNow < msmStop)
{...
When the Start time is greater than the stop time all is OK, but if the Start time is say 700(MSM) and the Stop is 150(MSM) the next morning that code fails. I did some searching but can't find a good search term for what I think I need.
This does not seem like an elegant approach... or is it?
if (msmStart > msmStop)
{ msmStop += 24;
}
if (msmNow >= msmStart && msmNow < msmStop)
{...
If your minutes roll over at midnight I think you can calculate the length of the interval by subtracting the recent time from the earlier time. Try it with a simple Arduino program. It may only work with byte or unsigned int values (ie rollover at 255 or 65535).
I've run into this one before. You need an if statement that checks if the start time is less than the end time. In each case you calculate the length of time differently.
These snippets tells us nothing about how your msmNow value is measured or derived. "minutes since midnight" suggests to me that the value should be the amount of minutes since the last midnight, resetting to 0 at the start of each day. The fact that it isn't working at the immediate next morning suggests that that is not the case, and it is probably "minutes since this specific midnight on this specific day", and it never resets to 0. This kind of thing is why the rules require posting a full sketch that demonstrates the problem.
I'm just spitballing though. I failed the remote viewing and telepathy classes in college.
Jiggy-Ninja:
These snippets tells us nothing about how your msmNow value is measured or derived.
Stay calm jiggy. Minutes since Midnight are the number of minutes since Midnight. There can only be one version of that since there is only one Midnight in my 24-hour days. But if it really matters with the problem here's the Black Magic and Voodoodoo to how I do it.
I already have that from the time Library. I'll just drop the seconds. In fact I won't even bother with that as 59-seconds error either way will not matter.
I add SECPERDAY before taking the modulus to force moonsetSec - moonriseSec to be a positive value (because the modulus operator does odd things with negative values, and making it unsigned won't help). I multiply SECPERDAY by 2 just to be on the safe side .
Once the night length is calculated, the decision as to whether its daytime or night time is here
void drawMoon() {
pixels.clear();
long tt = (timeOfDaySec - moonriseSec + SECSPERDAY * 2) % SECSPERDAY;
if (tt <= nightLenSec) {
// moon gets drawn here
}
pixels.show();
}
WaitSome:
Stay calm jiggy. Minutes since Midnight are the number of minutes since Midnight. There can only be one version of that since there is only one Midnight in my 24-hour days. But if it really matters with the problem here's the Black Magic and Voodoodoo to how I do it.
You have a problem with your code. You aren't able to fix that problem because you don't know what or where it is. That's why you come here to ask.
We know even less about your code than you do. We didn't write it, and it's our first time looking at it. That's why we need the whole picture.
First you show us a snippet that uses variables of unknown origin and unspecified meaning. We have to infer what they are for from the name. You're also adding some weird constant to one of the values, with no explanation for why you are doing that and how you came up with that value. There's also nothing obviously wrong with the window check you're doing below that.
I asked you to post the full sketch in bold. You apparently didn't read past the first sentence, and posted another snippet, one that shows you setting the msmNow variable in setup(), which is only ever run once and never again for the duration of the program. Is that the problem? I don't know, because I don't see where else you're updating this value because you refuse to post the full program.
There is a limit to how much obtuseness I'm willing to put up with.