Virtual pin altering function ran in Void loop()

Hello all,

So i am attempting to create a Reef Controller with my Arduino Mega, an Ethernet shield, and a relay board.

My goal is to have the default setup run (lights on and off at a certain time, Powerheads trading off to create currents) but be able to use Blynk to interface with it (get the temp, turn Powerheads off for 10 minutes for feeding.

So i have the following function that i run in Loop and it works to switch between powerheads every 30 seconds.

void powerHead()
{
if (second() > 30 && second() < 59)
{
digitalWrite(Relay_PH1, RELAY_ON);
digitalWrite(Relay_PH2, RELAY_OFF);
}
else
{
digitalWrite(Relay_PH1, RELAY_OFF);
digitalWrite(Relay_PH2, RELAY_ON);
}
}

now what im trying to add is a button to blynk that when activated halts the above action, turns off the above power heads, and waits 10 minutes before going back to default. What i have produced is below.

void powerHead()
{
if (feedButton == 1)
{
int startTime = minute();
while (minute() < (startTime + 10))
{
digitalWrite(Relay_PH1, RELAY_OFF);
digitalWrite(Relay_PH2, RELAY_OFF);
Serial.println((startTime + 10) - minute());
}
Blynk.virtualWrite(V2, 0);
}
else
{
if (second() > 30 && second() < 59)
{
digitalWrite(Relay_PH1, RELAY_ON);
digitalWrite(Relay_PH2, RELAY_OFF);
}
else
{
digitalWrite(Relay_PH1, RELAY_OFF);
digitalWrite(Relay_PH2, RELAY_ON);
}
}
}

It looks to me like it should work. I know that my arduino is picking up the updated virtual pin (set to feedButton) from my phone because i have it printing to serial but it does nothing. it just continues to switch between PH1 and PH2 every 30 seconds.

Please show me what im not seeing!

I think there is something wrong how you interrogate the button and pass the signal on to the Arduino code. Try something like this:

Declare an instance somewhere in the code to interrogate the button:

BLYNK_WRITE(V2) { // Button in Blynk app connected to virtual pin V2
feedButton = param[0].asInt(); // Reads the button state and saves it in you “local” variable
}

and delete the “Blynk.virtualWrite(V2, 0);” in your code above.

BLYNK_WRITE(V2)
{
int feedButton = param.asInt();
}

Above is how i read the pin state. I was already able to confirm i was getting the value properly by printing feedButton to the serial interface. and the “Blynk.virtualWrite(V2, 0);” portion above is to ensure that the button is turned back off after the 10 minutes is up.

OK, it was not really clear from your first post because it was not included in your code.