My sketch queries a Real Time Clock, and depending upon the time, a digital pin switches to HIGH or LOW. I've tried both the Time and TimeAlarms libraries, but have ran into issues, plus have since found the RTClib to work well for me.
I created a few different programmed events based on time, the first of which is triggered to ON at 6am everyday and triggers OFF at midnight every night and this works perfectly, producing a steady output voltage at the respective digital pin.
However, when I get to my second alarm, I fear my knowledge of the code is failing me and keeping me from asking the right question(s) of the RTC. My thought is that if the hour is 9 and the minute is 0 and equal to or less than 10, that this would create a test that can only be true from 9:00 to 9:09, but the output is buggy. Every time the sketch loops, the respective pin (D31=Relay_B) pulses HIGH for maybe 100 milliseconds, then goes LOW for the remainder of the loop. This pulsing process is repeated while the condition is true then goes LOW until tested true again.
define# TURN_ON 0 // TURN_ON/OFF was defined to accommodate relay polarity
define TURN_OFF 1
if (now.hour() == 9 && now.minute() >= 00 && now.minute() < 10) // FeedPump1, ON 9am
{
digitalWrite(Relay_B, TURN_ON);
Serial.print("\t");
Serial.println(F("First 10 Minute Feeding")); // Text printed to serial monitor
Serial.print("\t");
}
else // Turn off time for FeedPump1, OFF 9:10am
{
digitalWrite(Relay_B, TURN_OFF);
}
Relay_B is scheduled to be true twice daily, for 10 minutes each time. I don't know if it matters, but Relay_A will be true during both of Relay_B being true to it's tests. Can someone please enlighten me how to ask the most efficient questions as I keep getting tied up mentally in semantics of what is true at what given moment in time.
TYIA