Dual Load cell Reader Problem can you help?

Hi All,
I am using the following code on a Due board. It originally was written to read one load cell and I doubled everything up so it could read two load cells. I am getting dual readings as required on the serial monitor but it appears that the weight is been averaged using the Load0A & Load0B.
It seems to be ignoring Load1A & Load1B so I cannot calibrate the 2nd Load cell. Please can anyone help to see where I may be going wrong?
Thank you in advance Nevjc

// Arduino as load cell amplifier
// by Christian Liljedahl
// christian.liljedahl.dk

// Load cells are linear. So once you have established two data pairs, you can interpolate the rest.

// Step 1: Upload this sketch to your arduino board

// You need two loads of well know weight. In this example A = 10 kg. B = 30 kg
// Put on load A
// read the analog value showing (this is analogvalA)
// put on load B
// read the analog value B

// Enter you own analog values here
float load0A = 4.0; // kg
int analogval0A = 900; // analog reading taken with load A on the load cell

float load1A = 4.0;
int analogval1A = 100;

float load0B = 69.1; // kg
int analogval0B = 2976; // analog reading taken with load B on the load cell

float load1B = 69.1;
int analogval1B = 2200;
// Upload the sketch again, and confirm, that the kilo-reading from the serial output now is correct, using your known loads

float analogValueAverage0 = 0;
float analogValueAverage1 = 0;
// How often do we do readings?

int timeBetweenReadings = 200; // We want a reading every 200 ms;

void setup() {
Serial.begin(9600);
}

void loop() {
analogReadResolution(12);
int analogValue0 = analogRead(0);
int analogValue1 = analogRead(1);

// running average - We smooth the readings a little bit
analogValueAverage0 = 0.99analogValueAverage0 + 0.01analogValue0;
analogValueAverage1 = 0.99analogValueAverage1 + 0.01analogValue1;

// Is it time to print?
float load0 = analogToLoad(analogValueAverage0);
float load1 = analogToLoad(analogValueAverage1);

if (load0 < 0) { (load0=0);
}
if (load1 < 0) { (load1=0);
}
Serial.print(load0,1);
Serial.print(" ");
Serial.println(load1,1);
delay(10);
}

float analogToLoad(float analogval){

// using a custom map-function, because the standard arduino map function only uses int
float load0 = mapfloat0(analogval, analogval0A, analogval0B, load0A, load0B);
return load0;

float load1 = mapfloat1(analogval, analogval1A, analogval1B, load1A, load1B);
return load1;

}

float mapfloat0(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float mapfloat1(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Use code blocks! Don't post code directly.

What is this line doing in loop?

analogReadResolution(12);

Why do you have to set resolution every time?

This is NOT running average, or an average. Keep it if you like it:

  // running average - We smooth the readings a little bit
  analogValueAverage0 = 0.99*analogValueAverage0 + 0.01*analogValue0;
  analogValueAverage1 = 0.99*analogValueAverage1 + 0.01*analogValue1;

The following code will only return the first gauge reading:

float analogToLoad(float analogval){
   
  // using a custom map-function, because the standard arduino map function only uses int
  float load0 = mapfloat0(analogval, analogval0A, analogval0B, load0A, load0B);
  return load0;
  
  float load1 = mapfloat1(analogval, analogval1A, analogval1B, load1A, load1B);
  return load1;
  
}

Do this instead:

float analogToLoad0(float analogval){
   
  // using a custom map-function, because the standard arduino map function only uses int
  float load0 = mapfloat0(analogval, analogval0A, analogval0B, load0A, load0B);
  return load0;
}

float analogToLoad1(float analogval){  
  float load1 = mapfloat1(analogval, analogval1A, analogval1B, load1A, load1B);
  return load1;
  
}

You have no idea how a function works in C. Go do your reading.

Thanks luidr for your help. I see what you mean about the resolution I have changed it.
I have also changed the code as you have suggested and that also works fine now thank you.

Thanks for your help I will go and read up some more.
Regards Nevjc