Using both High and Low ATO to turn off port

Do you have a question on how to do something.
Ask in here.
Post Reply
Appleseed
Posts: 93
Joined: Sat Jun 30, 2012 9:21 am

Using both High and Low ATO to turn off port

Post by Appleseed »

Hi

I am trying to turn off port 4 on my relay if either of the ATO floats IsActive

I tired the following code but the second ato in the list takes precedence. If i put High in first them low works as expected and if low is first the high works. I am guessing that I need to add something else but i cant find what.


if (ReefAngel.HighATO.IsActive())
{
ReefAngel.Relay.On(Port4);
}
else
{
ReefAngel.Relay.Off(Port4);
}

if (ReefAngel.LowATO.IsActive())
{
ReefAngel.Relay.On(Port4);
}
else
{
ReefAngel.Relay.Off(Port4);
}

I would also like to have port4 only turn on after 60-120 seconads after the ato float returns to the "active" state.

thanks
Andy
Image
User avatar
brennyn21
Posts: 104
Joined: Mon Nov 23, 2020 5:40 pm

Re: Using both High and Low ATO to turn off port

Post by brennyn21 »

Sorry for the late reply, if i am understanding you want to have port4 on after either ato has been active for 60s. You can try the code below

adjust the activation delay to your liking

//Place in globals

Code: Select all

unsigned long highATOActiveTime = 0;
unsigned long lowATOActiveTime = 0;
const unsigned long activationDelay = 60000; // 60 seconds delay
//Place in void loop

Code: Select all

if (ReefAngel.HighATO.IsActive()) {
        if (highATOActiveTime == 0) {
            highATOActiveTime = millis(); // Start the timer if High ATO is active
        }
    } else {
        highATOActiveTime = 0; // Reset the timer if High ATO is inactive
    }

    // Check Low ATO state
    if (ReefAngel.LowATO.IsActive()) {
        if (lowATOActiveTime == 0) {
            lowATOActiveTime = millis(); // Start the timer if Low ATO is active
        }
    } else {
        lowATOActiveTime = 0; // Reset the timer if Low ATO is inactive
    }

    // Determine if either ATO has been active for at least 60 seconds
    if ((highATOActiveTime != 0 && millis() - highATOActiveTime >= activationDelay) ||
        (lowATOActiveTime != 0 && millis() - lowATOActiveTime >= activationDelay)) {
        ReefAngel.Relay.On(Port4); // Turn on Port 4 if either ATO is active for 60 seconds
    } else {
        ReefAngel.Relay.Off(Port4); // Turn off Port 4 if neither ATO is active for 60 seconds
    }
Sincerely, Brennyn
Post Reply