if statement orders and button presses

Hi,

can some one just give me a little pointer, here is what im trying to do.
An auger feeds onto a load cell and when the weight is reached it stops.
as the weight increases the speed slows down as shown in the code.

im just trying to get it to work as follows.
arduino is powered up.
scale is detected and settings loaded from eeprom (this works)
start button pressed.
serial print start once.
auger function runs untill weight reached.
auger stops

below is my current code (i will remove delay and change for millis)

#include <Wire.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h"

NAU7802 myScale; // Create an instance
SoftwareSerial mySerial (4, 5); //i2c for scale

int inPin = 12; // start button/serial command from master
int led = 13; // to see if button press is registered

int reading; //current reading push button
int previous = LOW; // previous reading puch button

//EEPROM
#define LOCATION_CALIBRATION_FACTOR 0
#define LOCATION_ZERO_OFFSET 10
bool settingsDetected = false;

//Average
#define AVG_SIZE 3
float avgWeights[AVG_SIZE];
byte avgWeightSopt = 0;

//Time Values
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
const long interval = 6000; // stable time for dispaly
const long interval1 = 30; //jitter time steady weight
const long dumpdelay = 300; //delay for emptying on target weight
long time = 0; // time since switch pressed
long debounce = 200; // debounce time

// More Bits
int Auger = 3; // pin motor driver pwm attached to
int Augerreverse = 4; // reverse pin on motor driver

void setup() {
  pinMode(inPin, INPUT);
  pinMode(led, OUTPUT);
  mySerial.begin(9600);
  Serial.begin(57600);
  Serial.println("Qwiic Scale");
  Serial.println("WAITING FOR START");
  pinMode(Auger, OUTPUT);
  startscale();


}

void loop() {

  int startbutton = digitalRead(12);
  //int statbuttoncounter = 0;
  int laststate = LOW;
  int counter = 0;

  if (startbutton != laststate) {
    if (laststate == HIGH) {
      counter++; // once press to start one to stop the auger function counter increment here
      Serial.println("on"); // Should happen when button pressed once


    }
    delay (500); // I WILL use millis here i promise

    laststate = HIGH; // sets last to high for next if statement

  }

  if (counter % 2 == 0 && laststate ==  LOW) { // using this to see if button has been pressed once or twice?
    Serial.println("Waiting");// waiting for button to be pressed
  }  else {
    auger();
  }
}





void startscale(void)
{
  Wire.begin();
  Wire.setClock(400000); //Qwiic Scale is capable of running at 400kHz if desired

  if (myScale.begin() == false)
  {
    Serial.println("Scale not detected. Please check wiring. Freezing...");
    while (1);
  }
  Serial.println("Scale detected!");

  readSystemSettings(); //Load zeroOffset and calibrationFactor from EEPROM

  myScale.setSampleRate(NAU7802_SPS_320); //Increase to max sample rate
  myScale.calibrateAFE(); //Re-cal analog front end when we change gain, sample rate, or channel

  Serial.print("Zero offset: ");
  Serial.println(myScale.getZeroOffset());
  Serial.print("Calibration factor: ");
  Serial.println(myScale.getCalibrationFactor());

}

void calibrateScale(void)
{
  Serial.println();
  Serial.println();
  Serial.println(F("Scale calibration"));

  Serial.println(F("Setup scale with no weight on it. Press a key when ready."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  myScale.calculateZeroOffset(64); //Zero or Tare the scale. Average over 64 readings.
  Serial.print(F("New zero offset: "));
  Serial.println(myScale.getZeroOffset());

  Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): "));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  //Read user input
  float weightOnScale = Serial.parseFloat();
  Serial.println();

  myScale.calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it
  Serial.print(F("New cal factor: "));
  Serial.println(myScale.getCalibrationFactor(), 2);

  Serial.print(F("New Scale Reading: "));
  Serial.println(myScale.getWeight(), 2);

  recordSystemSettings(); //Commit these values to EEPROM
}

//Record the current system settings to EEPROM
void recordSystemSettings(void)
{
  //Get various values from the library and commit them to NVM
  EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());
  EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());
}

//Reads the current system settings from EEPROM
//If anything looks weird, reset setting to default value
void readSystemSettings(void)
{
  float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg
  long settingZeroOffset; //Zero value that is found when scale is tared

  //Look up the calibration factor
  EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  if (settingCalibrationFactor == 0xFFFFFFFF)
  {
    settingCalibrationFactor = 0; //Default to 0
    EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  }

  //Look up the zero tare point
  EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);
  if (settingZeroOffset == 0xFFFFFFFF)
  {
    settingZeroOffset = 1000L; //Default to 1000 so we don't get inf
    EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);
  }

  //Pass these values to the library
  myScale.setCalibrationFactor(settingCalibrationFactor);
  myScale.setZeroOffset(settingZeroOffset);

  settingsDetected = true; //Assume for the moment that there are good cal values
  if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)
    settingsDetected = false; //Defaults detected. Prompt user to cal scale.
}


void readscale(void)
{
  long currentReading = myScale.getReading();
  float currentWeight = myScale.getWeight();
  // Serial.print("\tWeight; ");
  // Serial.print(currentWeight, 2);
  // Serial.println();

  int Weight = currentWeight; // do i need this??

  if (settingsDetected == false)

    Serial.print("\tScale not calibrated. Press 'c'.");

}

void auger(void)  {
  float currentWeight = myScale.getWeight();
  unsigned long currentMillis = millis();
  int laststate = 0;
  {
    if (currentWeight < 400) {
      Serial.println("  Speed 1");
      analogWrite(Auger, 255);
    }
    else if ((currentWeight >= 401) && (currentWeight <= 680)) {
      Serial.println("  Speed 2");
      analogWrite(Auger, 200);
    }
    else if ((currentWeight >= 681) && (currentWeight <= 700)) {
      Serial.println("  Speed 3");
      analogWrite(Auger, 120);
    }
    else if (currentWeight >= 700) {
      Serial.print("  STOP");
      analogWrite(Auger, 0);
    }

    if (currentWeight > 700 && currentMillis - previousMillis > interval1) {
      Serial.println("  Deposit");
      deposit();
    }
  }
}

void deposit(void)
{
  Serial.print("DONE");
//rest needs to be written
}

When this code runs it serial prints waiting over and over, it does not print start at all and when the button is pressed it prints speed 1 (From auger())

as i say i would like it to do nothing or say waiting untill the button is pressed and the it print start once and then run auger constantly untill it reaches its target.

im sure its just the order of my if statements but i have been trying for a day or so now and just seem to be going in circles.

thanks in advance
andy

Hi Andy,
I don't claim to be able to tell you all the problems but the one that stands out for me is:

  int laststate = LOW;

You are declaring it inside loop(), do you understand scope? As soon as loop() ends the varilable goes out of scope and loses whatever value it had might have got during loop(), so next time round it will be low again. You either need to declare it as static or make it global by declaring it before setup() along with your other global variables.
The same with counter, is that meant to keep its value? It doesn't, for the same reason.

I suspect Andy does not understand scope.

We also have global...

unsigned long currentMillis = 0;

And then later on in function auger() local variable with the same name...

unsigned long currentMillis = millis();

Andy, when you place the type name (e.g. "int") in front of the variable name you are declaring a brand new variable. This is completely separate from any previous variable (e.g. a global) with the same name.

This is the programming equivalent of having two children and calling them both "Bob". It's perfectly legal, but you'll have a very confusing time telling them apart if you try. Never create global and local variables with the same names.

If you have a variable defined then the correct way to assign a value to the exiting variable is...

currentMillis = millis();

Also your code never sets previousMillis. Therefore the timeout test in this code...

if (currentWeight > 700 && currentMillis - previousMillis > interval1) {

Is always true after 30ms.

You need to set previousMillis somehwere, probably...

   if (currentWeight > 700 && currentMillis - previousMillis > interval1) {
      Serial.println("  Deposit");
      deposit();
      previousMillis  = currentMillis;
    }

Hi.

Thanks for the replies, I'm not going to chance to look at it now untill Monday,

Alas it is true I do get confused with the structure of the programming language and have a very haphazard way of trial and error.

I'm definitely more or a practical learner than theory but feel I have made some progress whilst doing this project.

I'll take your ideas and suggestions and get back to you with my progress.

Thanks
Andy

Hi Andy,
I found this web site very helpful when I was learning C C Tutorial. There are plenty of others if you search for them.

I think you can define scope as being that a variable is only valid inside any {} it was defined in. Once you go past the final } it loses its value unless it is defined as static. If defined outside a particular pair of {} it's valid inside them, but not the other way around.

Hi all,

Ok ive been reading up and learning,

its true the more you do something the easier it gets,

my project is comming along nicley but alas once again i need a little pointer well two actually.

firstly. i Have the button pin 7 and this starts and stops the program but it only runs through once untill pressed again, if i press it during the loop it will stop whats its doing, this is not really required.

secondly, After so many deposits i need the scale to zero itself, i assume this is a case of reading the difference between the previous offset and current and adding the difference and storing it in the eeprom?

i can not work this out for the life of me at the moment.

the void with "record system settings" in blue has all the needed parts in as it works in the example sketch also attatched.

once again any help is greatly appreaciated.
my current code. Many parts are not used at the moment i need to tidy it up.

#include <Wire.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h"

NAU7802 myScale; // Create an instance
SoftwareSerial mySerial (4, 5); //i2c for scale


//EEPROM
#define LOCATION_CALIBRATION_FACTOR 0
#define LOCATION_ZERO_OFFSET 10
bool settingsDetected = false;

//Average
#define AVG_SIZE 3
float avgWeights[AVG_SIZE];
byte avgWeightSopt = 0;

//Time Values
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
const long interval = 6000; // stable time for dispaly
const long interval1 = 30; //jitter time steady weight
const long dumpdelay = 300; //delay for emptying on target weight
const long startAgain = 2500; //set lastButtonState
long time = 0; // time since switch pressed
long debounce = 200; // debounce time

// Variable states
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int depositCounter = 0;      // deposit counter for auto zero
int zeroAfter = 5;           // zero after this many deposits
int latchState = 0;          // set a latch high or low
float weight = 0; // weight value
float currentWeight = 0;

// Input and Output pins
int greenLED = 5; // start led connected here
int redLED = 6; // stop/finished led connected here
int buttonPin = 7; // start button connected here
int Auger = 3; // pin motor driver pwm attached to
int Augerreverse = 4; // reverse pin on motor driver

void setup() {    // run this once to setup up.
  pinMode(buttonPin, INPUT_PULLUP); //start button using internal pullup
  pinMode(greenLED, OUTPUT); // start led
  pinMode(redLED, OUTPUT); // stop/finished led
  pinMode(Auger, OUTPUT);

  mySerial.begin(9600);
  Serial.begin(57600);
  Serial.println("Qwiic Scale");
  Serial.println("WAITING FOR START");


  startscale();
  float currentWeight = myScale.getWeight();
  if (currentWeight >= 5) {
    calibrateScale();
  } else  {
  }


}

void loop() {



  long currentReading = myScale.getReading();
  float currentWeight = myScale.getWeight();
  // Serial.print("\tWeight; ");
  // Serial.print(currentWeight, 2);
  // Serial.println();

  float weight = currentWeight; // do i need this??

  if (settingsDetected == false)

    Serial.print("\tScale not calibrated. Press 'c'.");




  buttonState = digitalRead(buttonPin); // go and see what the button is doing

  if (buttonState != lastButtonState) {
    if (buttonState == LOW) {
      buttonPushCounter++; // may not need this bit
      Serial.println("Start"); // Ok Im Starting
      //  Serial.println(buttonPushCounter); // may not need this either


    } else {
      Serial.println("Paused"); // come on press the button
    }
    delay(1); // replace with millis when i know it works
  }
  lastButtonState = buttonState; // remember this for the loop when it repeats

  if (depositCounter == zeroAfter) {

    zero();
    //depositCounter = 0;
  } else {

    if (buttonPushCounter % 2 == 0 ) {
      digitalWrite(greenLED, HIGH);
    } else {
      digitalWrite(greenLED, LOW); //
      digitalWrite(redLED, HIGH); //
      Serial.println(weight);
      Serial.println(depositCounter); // check to see this is incrementing

      if (currentWeight < 400) {
        Serial.println("  Speed 1");
        analogWrite(Auger, 255);
      }
      else if ((currentWeight >= 401) && (currentWeight <= 680)) {
        Serial.println("  Speed 2");
        analogWrite(Auger, 200);
      }
      else if ((currentWeight >= 681) && (currentWeight <= 700)) {
        Serial.println("  Speed 3");
        analogWrite(Auger, 120);
      }
      else if (currentWeight >= 700) {
        Serial.println("STOP");
        analogWrite(Auger, 0);
        deposit();
        //latchState = HIGH;
        depositCounter ++;
        digitalWrite(redLED, LOW);


      }
      if (buttonState == LOW && currentWeight >= 700) {
        lastButtonState = HIGH;
      }

    }
  }
}


void startscale(void)
{
  Wire.begin();
  Wire.setClock(400000); //Qwiic Scale is capable of running at 400kHz if desired

  if (myScale.begin() == false)
  {
    Serial.println("Scale not detected. Please check wiring. Freezing...");
    while (1);
  }
  Serial.println("Scale detected!");

  readSystemSettings(); //Load zeroOffset and calibrationFactor from EEPROM

  myScale.setSampleRate(NAU7802_SPS_320); //Increase to max sample rate
  myScale.calibrateAFE(); //Re-cal analog front end when we change gain, sample rate, or channel

  Serial.print("Zero offset: ");
  Serial.println(myScale.getZeroOffset());
  Serial.print("Calibration factor: ");
  Serial.println(myScale.getCalibrationFactor());

}

void calibrateScale(void)
{
  Serial.println();
  Serial.println();
  Serial.println(F("Scale calibration"));

  Serial.println(F("Setup scale with no weight on it. Press a key when ready."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  myScale.calculateZeroOffset(32); //Zero or Tare the scale. Average over 64 readings.
  Serial.print(F("New zero offset: "));
  Serial.println(myScale.getZeroOffset());

  Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): "));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  //Read user input
  float weightOnScale = Serial.parseFloat();
  Serial.println();

  myScale.calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it
  Serial.print(F("New cal factor: "));
  Serial.println(myScale.getCalibrationFactor(), 2);

  Serial.print(F("New Scale Reading: "));
  Serial.println(myScale.getWeight(), 2);

  recordSystemSettings(); //Commit these values to EEPROM
}

[color=blue]//Record the current system settings to EEPROM
void recordSystemSettings(void)
{
  //Get various values from the library and commit them to NVM
  EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());
  EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());
}

//Reads the current system settings from EEPROM
//If anything looks weird, reset setting to default value
void readSystemSettings(void)
{
  float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg
  long settingZeroOffset; //Zero value that is found when scale is tared

  //Look up the calibration factor
  EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  if (settingCalibrationFactor == 0xFFFFFFFF)
  {
    settingCalibrationFactor = 0; //Default to 0
    EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  }

  //Look up the zero tare point
  EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);
  if (settingZeroOffset == 0xFFFFFFFF)
  {
    settingZeroOffset = 1000L; //Default to 1000 so we don't get inf
    EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);
  }

  //Pass these values to the library
  myScale.setCalibrationFactor(settingCalibrationFactor);
  myScale.setZeroOffset(settingZeroOffset);

  settingsDetected = true; //Assume for the moment that there are good cal values
  if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)
    settingsDetected = false; //Defaults detected. Prompt user to cal scale.
}[/color]


void deposit(void)

{
  Serial.println("Deposit");

  buttonPushCounter ++;
}


void zero(void)

{
  long settingZeroOffset;

  Serial.println("Zero Scale");
  myScale.calculateZeroOffset(64);
  //  Serial.println("Done");
  myScale.setZeroOffset(settingZeroOffset);

  depositCounter = 0;

}

This code is a working example with the Zero function working.

/*
  Use the Qwiic Scale to read load cells and scales
  By: Nathan Seidle @ SparkFun Electronics
  Date: March 3rd, 2019
  License: This code is public domain but you buy me a beer if you use this
  and we meet someday (Beerware license).

  This example shows how to setup a scale complete with zero offset (tare),
  and linear calibration.

  If you know the calibration and offset values you can send them directly to
  the library. This is useful if you want to maintain values between power cycles
  in EEPROM or Non-volatile memory (NVM). If you don't know these values then
  you can go through a series of steps to calculate the offset and calibration value.

  Background: The IC merely outputs the raw data from a load cell. For example, the
  output may be 25776 and change to 43122 when a cup of tea is set on the scale.
  These values are unitless - they are not grams or ounces. Instead, it is a
  linear relationship that must be calculated. Remeber y = mx + b?
  If 25776 is the 'zero' or tare state, and 43122 when I put 15.2oz of tea on the
  scale, then what is a reading of 57683 in oz?

  (43122 - 25776) = 17346/15.2 = 1141.2 per oz
  (57683 - 25776) = 31907/1141.2 = 27.96oz is on the scale

  SparkFun labored with love to create this code. Feel like supporting open
  source? Buy a board from SparkFun!
  https://www.sparkfun.com/products/15242

  Hardware Connections:
  Plug a Qwiic cable into the Qwiic Scale and a RedBoard Qwiic
  If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
  Open the serial monitor at 9600 baud to see the output
*/

#include <Wire.h>
#include <EEPROM.h> //Needed to record user settings

#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_NAU8702

NAU7802 myScale; //Create instance of the NAU7802 class

//EEPROM locations to store 4-byte variables
#define LOCATION_CALIBRATION_FACTOR 0 //Float, requires 4 bytes of EEPROM
#define LOCATION_ZERO_OFFSET 10 //Must be more than 4 away from previous spot. Long, requires 4 bytes of EEPROM

bool settingsDetected = false; //Used to prompt user to calibrate their scale

//Create an array to take average of weights. This helps smooth out jitter.
#define AVG_SIZE 4
float avgWeights[AVG_SIZE];
byte avgWeightSpot = 0;

void setup()
{
  Serial.begin(9600);
  Serial.println("Qwiic Scale Example");

  Wire.begin();
  Wire.setClock(400000); //Qwiic Scale is capable of running at 400kHz if desired

  if (myScale.begin() == false)
  {
    Serial.println("Scale not detected. Please check wiring. Freezing...");
    while (1);
  }
  Serial.println("Scale detected!");

  readSystemSettings(); //Load zeroOffset and calibrationFactor from EEPROM

  myScale.setSampleRate(NAU7802_SPS_320); //Increase to max sample rate
  myScale.calibrateAFE(); //Re-cal analog front end when we change gain, sample rate, or channel 

  Serial.print("Zero offset: ");
  Serial.println(myScale.getZeroOffset());
  Serial.print("Calibration factor: ");
  Serial.println(myScale.getCalibrationFactor());
}

void loop()
{
  if (myScale.available() == true)
  {
    long currentReading = myScale.getReading();
    float currentWeight = myScale.getWeight();

    Serial.print("Reading: ");
    Serial.print(currentReading);
    Serial.print("\tWeight: ");
    Serial.print(currentWeight, 2); //Print 2 decimal places

    avgWeights[avgWeightSpot++] = currentWeight;
    if(avgWeightSpot == AVG_SIZE) avgWeightSpot = 0;

    float avgWeight = 0;
    for (int x = 0 ; x < AVG_SIZE ; x++)
      avgWeight += avgWeights[x];
    avgWeight /= AVG_SIZE;

    Serial.print("\tAvgWeight: ");
    Serial.print(avgWeight, 2); //Print 2 decimal places

    if(settingsDetected == false)
    {
      Serial.print("\tScale not calibrated. Press 'c'.");
    }

    Serial.println();
  }

  if (Serial.available())
  {
    byte incoming = Serial.read();

    if (incoming == 't') //Tare the scale
      myScale.calculateZeroOffset();
    else if (incoming == 'c') //Calibrate
    {
      calibrateScale();
    }
  }
}

//Gives user the ability to set a known weight on the scale and calculate a calibration factor
void calibrateScale(void)
{
  Serial.println();
  Serial.println();
  Serial.println(F("Scale calibration"));

  Serial.println(F("Setup scale with no weight on it. Press a key when ready."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  myScale.calculateZeroOffset(64); //Zero or Tare the scale. Average over 64 readings.
  Serial.print(F("New zero offset: "));
  Serial.println(myScale.getZeroOffset());

  Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): "));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(10); //Wait for user to press key

  //Read user input
  float weightOnScale = Serial.parseFloat();
  Serial.println();

  myScale.calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it
  Serial.print(F("New cal factor: "));
  Serial.println(myScale.getCalibrationFactor(), 2);

  Serial.print(F("New Scale Reading: "));
  Serial.println(myScale.getWeight(), 2);

  recordSystemSettings(); //Commit these values to EEPROM
}

//Record the current system settings to EEPROM
void recordSystemSettings(void)
{
  //Get various values from the library and commit them to NVM
  EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());
  EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());
}

//Reads the current system settings from EEPROM
//If anything looks weird, reset setting to default value
void readSystemSettings(void)
{
  float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg
  long settingZeroOffset; //Zero value that is found when scale is tared

  //Look up the calibration factor
  EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  if (settingCalibrationFactor == 0xFFFFFFFF)
  {
    settingCalibrationFactor = 0; //Default to 0
    EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  }

  //Look up the zero tare point
  EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);
  if (settingZeroOffset == 0xFFFFFFFF)
  {
    settingZeroOffset = 1000L; //Default to 1000 so we don't get inf
    EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);
  }

  //Pass these values to the library
  myScale.setCalibrationFactor(settingCalibrationFactor);
  myScale.setZeroOffset(settingZeroOffset);

  settingsDetected = true; //Assume for the moment that there are good cal values
  if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)
    settingsDetected = false; //Defaults detected. Prompt user to cal scale.
}

Thanks again
Andy

Not sure why the process only runs once. I'd simplify it and have a boolean that controls whether or not to run the scale rather than counting presses. Set it false to start. Whenever you detect a press, flip it.

For calibration, you can do the same thing you do for zero - count deposits and after some number, calibrate.

Hi Andy,

I admire your attempts to learn.

When it comes to other people's code I am not the best so this is just general comment, someone else might be more helpful and more specific.

I know you are new to programming but this:

the void with "record system settings"

is wrong. The word you are looking for is 'function': they are called functions. The word before the function name, in this case 'void' signifies the kind of variable the function returns, with void meaning it does not return any variable.

You need to learn about state machines, doing more than 1 thing at once and you need to learn to break your code into functions. Each function should do a well defined single task. loop() should contain only calls to your functions. Once you do that your code become much easier to read and much easier to debug.

Read:
Demonstration for several things at the same time
Look at my code in Using Nextion displays with Arduno, which shows how I break code into individual functions each with its own task.