basic if else question

I’m probably the one millionth newbie to ask this type of question.

I’m trying to program a statement filter of sorts.

This is a template i’ll be using for only 5 pots at the moment.

pot1_val (read from pot1_raw) is from 0-1024 (actual
pot1_cal_1 is 540 (but will become temporarily variable during a later programmed in calibration stage)
pot1_cal_2 is 580 (but will become temporarily variable during a later programmed in calibration stage)

output variables

i need it to do a statement in which it outputs towards three others
Variable X1
Variable X2
Variable X3

so here’s the code i’ve worked on my loop section so far.
I’ve left out my intial setup on purpose assume each has a int var

}

void loop(){

pot1_val = analogRead(pot1_raw);

if (pot1_val <= pot1_cal_1)
{pot1_val_x1 == pot1_val;
}
else if (pot1_val >= pot1_cal_1=1 && pot1_val <= pot1_cal_2-1)
{pot1_val_x2 == pot1_val;
}
else if (pot1_val >= pot1_cal_2)
{pot1_val_x3 == pot1_val;}

it gives me the error

sketch_aug07a.cpp: In function ‘void loop()’:
sketch_aug07a:108: error: lvalue required as left operand of assignment

any ideas?

else if (pot1_val >= pot1_cal_1**=1** u&& pot1_val <= pot1_cal_2-1)

Why is that in there?

Silencer1ami:

 void loop(){

pot1_val = analogRead(pot1_raw);
 
  if (pot1_val <= pot1_cal_1)
     {pot1_val_x1 == pot1_val;
   }
   else if (pot1_val >= pot1_cal_1=1 && pot1_val < pot1_cal_2-1)
             {pot1_val_x2 == pot1_val;
   }
   else if (pot1_val >= pot1_cal_2)
             {pot1_val_x3 == pot1_val;}




You are using == which is a comparison operator, when you want =, which is an assignment operator. In an else statement, you can assume that the previous test was false, so you don't need to repeat it. You also used =1 in the second test, which was the source of the error message. I also changed a test <= foo-1 to test < foo, but I'm not sure that is what you wanted. You want something like:



void loop(){
  pot1_val = analogRead(pot1_raw);
 
  if (pot1_val <= pot1_cal_1) {
       pot1_val_x1 = pot1_val;

} else if (pot1_val < pot1_cal_2) {
        pot1_val_x2 = pot1_val;

} else {
         pot1_val_x3 = pot1_val;
   }
}

i cannot believe that's in there...dope it's what i get for cram learning at lunch break. That's fixed the error!
thanks for the help!