// below is the temperature compensation code. See explanation in file ardbeescale.docx int TextLength = sizeof(Text)/sizeof(Text[0]); // Text is an array (global variable) containing the last 6 external temperature measures for( int index = 0; index < TextLength; index = index + 1 ){ // right shift Text array by 1 and update Text[0] Text[TextLength-index-1]=Text[TextLength-index-2]; } Text[0] = newTemp; // newTemp should contain the latest temperature measure int deltaTextLength = sizeof(deltaText)/sizeof(deltaText[0]); // deltaText is an array (global variable) containing the last 5 temperature changes for( int index = 0; index < deltaTextLength; index = index + 1 ){ // right shift deltaText array by 1 and update deltaText[0] deltaText[deltaTextLength-index-1]=deltaText[deltaTextLength-index-2]; } deltaText[0] = newTemp - Text[1]; float totalDeltaTlc = 0; // will contain the sum of loaf cell temprature changes, after calculation of them here below float expFactor = (float) (doWorkIntervalSeconds+8)/60 / (float) TIMECONSTANT; // needed for calculating load cell temperature (4 lines below) int deltaTlcLength = sizeof(deltaTlc)/sizeof(deltaTlc[0]); for( int index = 0; index < deltaTlcLength; index = index + 1 ){ // recalculate all the load cell temperature changes of the past deltaTlc[index] = deltaText[index] * (1-exp(-(expFactor*(index+1)))); // load cell temperature change resulting from external temperature step totalDeltaTlc += deltaTlc[index]; } float Tlc = Text[5] + totalDeltaTlc; // now we are getting the real load cell temperature float wCompensation = (Tlc - T_EXT_INIT) * WEIGHTSLOPE; // and we can therefore calculate the compensation that need to be substracted from the measured weight weight -= wCompensation; // this is the temperature compensated weight