Stop Increment by more than 1

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);
    TestNumberFlag = false;
  //SEND TO THINGSPEAK//////////////////////////////////////////
  Blynk.virtualWrite(V120, TestNumber, TestKH, tempHValue); 
  //UPDATE FLAGS////////////////////////////////////////////////
  DataFlag = true;
  TestComplete = false;

Do your serial.print() statements show you that loop is going twice before your thing is reset?

Its a bit hard to attach serial print as there is no connection with the computer. Also before the attached function comes into play you have to go through an entire test which takes up to 20 minutes! I will see how i can rig something up

i guess hand waving will have to do.

where is this code that operates on the value being incremented?

why is this code there?

TestNumber = svTestNumber + 1; EEPROM.put(20, TestNumber)

I tried using a boolean to stop it repeating

this isn't incrementing TestNumber ... TestNumber are different svTestNumber are different.

why not TestNumber++;

svTestNumber is equal to TestNumber taken from Eeprom. 1 is added to svTestNumber and allocated to TestNumber which is then saves back to Eeprom.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.