Scale Program Issues "if... else" conditional problems

Hi all
I’m working on making an automatic weighing scale for packing salad greens for the farm. i’m having a hard time getting the tare and the high weight to register properly. Checked to make sure everything physically works. I think it’s something with my program.

Here’s my software so far.

any advice? what am I missing?

#include <HX711.h>

HX711 scale(A1, A0);

int simp_fact(pow(2,12));
int tare_state = 0;
int high_state= 0;

void setup()
{
Serial.begin(9600);
pinMode(2,INPUT) ;
pinMode(3,INPUT) ;
scale.set_scale();
scale.tare();
delay (100);

}
void loop() {

int high_weight(10000);
float tare_off(0);
int cali_weight ((((scale.get_units(20)-tare_off)/simp_fact)*9.475)+1.35);
Serial.print("the signal is: ");
Serial.println (cali_weight);
Serial.print ("the high weight is: ");
Serial.println(high_weight);
Serial.print ("the status of tare is ");
Serial.println (tare_off);

tare_state=digitalRead(2);
if (tare_state == HIGH);
{tare_off = scale.get_units (2);
Serial.println (“the tare has been pressed”);

high_state = digitalRead(3);
if (high_state == HIGH);
{high_weight = cali_weight;
Serial.println (“the high weight has been pressed”);

}

if (high_state == HIGH);
{...

Notice the ; after the if, that's an empty block. You're saying if state is high, then do nothing. Then, your {...} gets always executed anyways since it's also a valid block. Your're not supposed to have that ; there.

thanks I knew it was something simple but missed the detail

any idea why when I change the state to high it's not altering the integers to the current scale reading???

Those variables all look like they are local to loop. So you create them at the beginning of loop then you print them then you might give them a value. Then loop ends and those variables go out of scope and cease to exist. Then loop repeats and you create those variables new again.

Google "C++ scope" and do some study and you will understand.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool but it’s still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code.

That code doesn’t even compile. If you do the Auto Format and then check the resulting indentation you’ll see there is clearly a problem of unbalanced braces.

Also, this:

int cali_weight ((((scale.get_units(20)-tare_off)/simp_fact)*9.475)+1.35);

is quite strange. I guess you meant to do this:

int cali_weight = ((((scale.get_units(20)-tare_off)/simp_fact)*9.475)+1.35);

A quick test indicates they may work the same but the latter makes it much more clear what the intent of the code is.