Hi Paul
Yes this was indeed just a dummy to show the branch requirement, that is why it did not matter about the variable, I just assigned it to a fixed value to see the result of branching without having to use the analog input for decision.
The reason I never need to get back to the main loop is that the application is a sensor that has 2 different data sets depending on the initial startup condition. So if the sensor value is X at startup the program should go to Branch 1 and if it is Y then it should go to Branch 2. Once in a particular branch, there is a calibration routine. For the first 4 seconds I read the sensors max value (with full load) and in the next 4 seconds I read its MIN value (with no load). Once it is calibrated, the sensor is used to make measurements until such time it is turned off, so i never need to get back to the main loop.
I have to find another way to do the calibration step. Below is what I was using which worked fine on the UNO, I guess I will have to use a few FOR loops?
static int sampleLow = 1024;
static int sampleHigh = 0;
while (millis() < 8000UL)
{
if (millis() <4000) {
lcd.setCursor(0, 0);
lcd.print("Measure");
lcd.setCursor(0, 1);
lcd.print("High");
Serial.println("Measuring High");
}
if (millis() >4000) {
lcd.setCursor(0, 0);
lcd.print(" Remove ");
lcd.setCursor(0, 1);
lcd.print(" Load");
Serial.println(" Remove Load");
delay (200);
}
// MEASURE
int sensorVal = analogRead(A0);
// MATH
sampleLow = min(sampleLow, sensorVal);
sampleHigh = max(sampleHigh, sensorVal);
}