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!