Do you have the code for calculating the ounces?
To edit what you've got already you probably want something similar to this:
#include "HX711.h"
#include "KTS_Button.h"
#define DOUT 8
#define CLK 7
#define tarePin 9 //Tare button at pin 9
#define unitsPin 6 //Units button at pin 6
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float tareVal = 0;
float i = 0;
HX711 scale;
float calibration_factor = 220; //calibration factor for 5kg amazon load cell with gain 128 and grams as units
KTS_Button tareButton(tarePin);
KTS_Button unitsButton(unitsPin);
enum Unit {
grams = 0,
ounces,
NUM_UNITS
}; Unit currentUnit = grams;
void cycleUnits() {
currentUnit = currentUnit + 1;
if (currentUnit == NUM_UNITS)
currentUnit = 0;
}
void setup() {
Serial.begin(9600);
pinMode(SCK, OUTPUT);
lcd.begin(16, 2);
scale.begin(DOUT, CLK, 128); //Start communications to HX711 pins and set gain factor 64|128 are options on Channel A
scale.set_scale(calibration_factor); //Required during scale startup, scale factor will be adjusted in main loop for calibration
scale.tare(); //Reset the scale to 0
}
void loop() {
if (tareButton.read() == SINGLE_PRESS) {
scale.tare();
}
if (unitsButton.read() == SINGLE_PRESS) {
cycleUnits();
lcd.clear();
lcd.print("Weight: ");
switch (currentUnit) {
case grams:
lcd.print(scale.get_units * (0.035274)(4), 1);
lcd.print("g");
break;
case ounces:
// replace with ounces calc/print
lcd.print("oz");
break;
}
}
}
But you've got to get some button debouncing in there (easiest to use a button library), or you'll be playing roulette as to whether it lands on grams or ounces I've used my own in the example above KTS_Button.h (3.6 KB) but any will do.
This is also assuming that hitting the units button, means you want to change the units to the next unit, and then also display the weight?
I've only tested this as far as serial prints, the buttons and the cycling/printing of the units. I haven't tested anything to do with the scale (I had it all commented out).