I have a snippet of code whereby I am carrying out a dKH test with my DIY dKH machine and i need to keep track of the test number as when it gets to a certain number I need to calibrate. What tends to happen is instead of incrementing by 1 it increments by 2 and sometimes 1. What is happening i assume is the while the condition to check the test number and increment is happening the loop goes round again before it can set the test flag to a false state. Any ideas on how to resolve this would be appreciated. below is my code
void dKHEvaluate()
{
if (TestComplete)
{
svPump2_Vol_Drop = EEPROM.get(50, Pump2_Vol_Drop);
//dKH FUNCTION/////////////////////////////////////////////////
Dosage1 = svPump2_Vol_Drop * 20; //15; //CHANGE TO 20 FOR NEXT VERSION
Dosage2 = svPump2_Vol_Drop * TotalDrops;
TotalACIDused = Dosage1 + Dosage2;
TestKH = (TotalACIDused / 60.0) * 280.0;
TestNumberFlag = true;
}
//TEST NUMBER FUNCTION////////////////////////////////////////
if (TestNumberFlag)
{
svTestNumber = EEPROM.get(20, TestNumber);
//TEST NUMBER UPDATE/////////////////////////////////////////////////
TestNumber = svTestNumber + 1;
EEPROM.put(20, TestNumber);
EEPROM.commit();
TestNumberFlag = false;
}
//SEND TO THINGSPEAK//////////////////////////////////////////
Blynk.virtualWrite(V120, TestNumber, TestKH, tempHValue);
//UPDATE FLAGS////////////////////////////////////////////////
DataFlag = true;
TestComplete = false;
}