Help with If statements using RTC

I have built an electronic candle that has different patterns at various hours of the day. I also built in two different scents that are released via a solenoid valve for 3 seconds at the beginning of some hours, then a fan that runs for another 3 minutes blowing the scent into the air.....that's the plan anyway.

I have used If statement with RTC on other projects but only needed the hour function. Now I need to use the minutes and seconds which shouldn't be difficult! BUT I have tried a variety of codes without success!

Code is attached but the problem these "if" statements are never true and don't execute:

//Red Theme with scent+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ((now.hour()== 5) && (now.minute() == 0) && (now.second() == (0 || 1 || 2 || 3)))
{
Serial.print("Cyclone Theme befoe Red Theme");
Serial.println();
digitalWrite (rm, HIGH);
cylonRoof () ;
rgbRain ();
digitalWrite(rfan, HIGH);
digitalWrite(rvalve1, HIGH);//Morning scent - most outboard
}

if ((now.hour()== 5) && (now.minute () == 0) && (now.second() >= 3))
{
Serial.print("Cyclone Theme no scent with fan");
Serial.println();
cylonRoof () ;
rgbRain ();
digitalWrite(rvalve1, LOW);//Morning scent off

}
///leaves fan on for 3 minutes before turning off
if ((now.hour()== 5) && ((now.minute() >0) && (now.minute() < 3)))
{
Serial.print("Red Theme no scent w fan off");
Serial.println();
digitalWrite(rfan, LOW);
laserLights () ;
roofRainbow ();
rgbRed();
///Maintains Red Theme for an hour
if ((now.hour()== 6 ) && (now.minute() >=4))
{
Serial.print("Red Theme no scent w fan off");
Serial.println();
laserLights () ;
roofRainbow ();
rgbRed();
}

CM10-clock_reset.ino (14.6 KB)

now.second() == (0 || 1 || 2 || 3))

You can not do that. It's valid C syntax but produces nonsense. it is equivalent to

now.second() == 1

you have repetitive tests for the hour. You should nest the units, like:
if hour = 5
{
if minute = 0
{
if second = whatever
}
else
{...

I would never use RTC times to control a 3 second timed output. I would use delay() or a millis() timer for that. I would test for when time units change, not continuously poll and sort out the values each and every time through loop, redundantly performing the same actions over and over after they've already been set.

Like:

if currentHour != now.hour
{
currentHour = now. hour
... //perform hour change actions
}

Ok, how do I turn it on for 3 seconds at the beginning of each hour?

Kingdragon8:
Ok, how do I turn it on for 3 seconds at the beginning of each hour?

Kingdragon8:
Ok, how do I turn it on for 3 seconds at the beginning of each hour?

turn it on
delay(3000);
turn it off

Thanks! I thought a delay would constantly be called during the hour, not just once? That is why I haven't used either delay technique....?

The trick is to turn it on for 3 seconds when the hour changes

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