Dear Blynkers,
I wracked my head around this issue but cant seem to get it to work. I have a CountDown function which takes 2 parameters, CountLimit which is defined in the variables statements in the initial part of the sketch and CountRemain which gets its value from the CountLimit minus millis().
The function has a timer interval set 50L in the setup. The correct value shows up on the diplay widget but it does not count down.
Any ideas anyone?
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
//COUNTDOWN TIMER VARIABLES//
char count[9];
#define totalSec(_time_) (_time_ % SECS_PER_MIN)
#define totalMin(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define totalHr(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
unsigned long CountLimit1 = DeGasOn1 / 1000; //Millis > Seconds
unsigned long CountLimit2 = DeGasOn2 / 1000; //Millis > Seconds
unsigned long CountLimit3 = DeGasOn3 / 1000; //Millis > Seconds
unsigned long CountLimit4 = DeGasOn4 / 1000; //Millis > Seconds
unsigned long CountLimit5 = DeGasOn5 / 1000; //Millis > Seconds
unsigned long CountLimit6 = DeGasOn6 / 1000; //Millis > Seconds
unsigned long CountRemain;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
pinMode(CircPin, OUTPUT);
pinMode(FeedPin, OUTPUT);
pinMode(CO2Pin, OUTPUT);
pinMode(SensorPin, INPUT);
pinMode(LedCO2, OUTPUT);
pinMode(LedFeed, OUTPUT);
pinMode(LedCirc, OUTPUT);
setSyncInterval(50);
timer.setInterval(1000L, ClockDisplay);
timer.setInterval(50L, RunStateMachine);
timer.setInterval(50L, CountDown);
}
BLYNK_WRITE(V2)
{
DegasPd = param.asInt();
Blynk.virtualWrite(V3, DegasPd); //Send value to gauge display
}
BLYNK_WRITE(V4) //Numeric Input Widget
{
CalcSt = (param.asFloat()*100);
CycleTime = map(CalcSt, 0, 10, 0, 30000);
Blynk.virtualWrite(V5, (CalcSt/100)); //Send value to gauge display
Serial.print(CalcSt/100);
Serial.print(" : " );
Serial.println();
}
void CountDown()
{
unsigned long ts;
ts = millis() / 1000;
if ((CountRemain >= 0)&&(DegasPd == 1))
{
CountRemain = CountLimit1 - ts;
int Sec = totalSec(CountRemain);
int Min = totalMin(CountRemain);
int Hr = totalHr(CountRemain);
CountRemain = CountLimit1 - ts;
sprintf(count, "Next DeGas In %02d:%02d:%02d", Hr, Min, Sec);
Blynk.virtualWrite(V6, count);
Serial.println(" Degas " );
Serial.print(DegasPd);
}
else if ((CountRemain >= 0)&&(DegasPd == 2))
{
CountRemain = CountLimit2 - ts;
int Sec = totalSec(CountRemain);
int Min = totalMin(CountRemain);
int Hr = totalHr(CountRemain);
CountRemain = CountLimit2 - ts;
sprintf(count, "Next DeGas In %02d:%02d:%02d", Hr, Min, Sec);
Blynk.virtualWrite(V6, count);
Serial.println(" Degas " );
Serial.print(DegasPd);
}
else if ((CountRemain >= 0)&&(DegasPd == 3))
{
CountRemain = CountLimit3 - ts;
int Sec = totalSec(CountRemain);
int Min = totalMin(CountRemain);
int Hr = totalHr(CountRemain);
CountRemain = CountLimit3 - ts;
sprintf(count, "Next DeGas In %02d:%02d:%02d", Hr, Min, Sec);
Blynk.virtualWrite(V6, count);
Serial.println(" Degas " );
Serial.print(DegasPd);
}
else if ((CountRemain >= 0)&&(DegasPd == 4))
{
CountRemain = CountLimit4 - ts;
int Sec = totalSec(CountRemain);
int Min = totalMin(CountRemain);
int Hr = totalHr(CountRemain);
CountRemain = CountLimit4 - ts;
sprintf(count, "Next DeGas In %02d:%02d:%02d", Hr, Min, Sec);
Blynk.virtualWrite(V6, count);
Serial.println(" Degas " );
Serial.print(DegasPd);
}
else if ((CountRemain >= 0)&&(DegasPd == 5))
{
CountRemain = CountLimit5 - ts;
int Sec = totalSec(CountRemain);
int Min = totalMin(CountRemain);
int Hr = totalHr(CountRemain);
CountRemain = CountLimit5 - ts;
sprintf(count, "Next DeGas In %02d:%02d:%02d", Hr, Min, Sec);
Blynk.virtualWrite(V6, count);
Serial.println(" Degas " );
Serial.print(DegasPd);
}
else if ((CountRemain >= 0)&&(DegasPd == 6))
{
CountRemain = CountLimit6 - ts;
int Sec = totalSec(CountRemain);
int Min = totalMin(CountRemain);
int Hr = totalHr(CountRemain);
CountRemain = CountLimit6 - ts;
sprintf(count, "Next DeGas In %02d:%02d:%02d", Hr, Min, Sec);
Blynk.virtualWrite(V6, count);
Serial.println(" Degas " );
Serial.print(DegasPd);
}
}