"If" statement issue


hello;

i have program measures resistance. works except "if" statement @ end of following code:

long resistance_array = 0; // sum of resistance measurements taken
int measurement_count  = 0; // current measurement number
float resistance_reading = 0; // calculated resistance value

float resistance_min = 100; // minimum  resistance
float resistance_max = 150;  // maximum  resistance
int pass_fail = 0;


//**************************************************************************************************************************************************************

void setup() {
    serial.begin(9600);  // set rate data transfer
}

//**************************************************************************************************************************************************************

void loop(){

// measure resistance
  measurement_count = 0; // reset measurement count
  resistance_array = 0;  // reset sum of resistance measurements taken 
  resistance_reading = 0; // reset calculated resistance value

    while (measurement_count < 200) { // take set number of resistance readings , add them up
        resistance_array += analogread(a0);
        measurement_count++;
        delay(1);// delay allow arduino input refresh
    }
  resistance_reading = (((resistance_array / 200)*.004882813)/.004); // average 200 resistance measurements together, multiply 4.88,mv / bit, , divide 4ma resistance
 
// check if reading in spec

if (resistance_reading >  resistance_min & resistance_reading <  resistance_max) {pass_fail = 1;} // pass if in spec
      else  {pass_fail = 0;} // fail if not in spec


//**** things go wrong========
   if (pass_fail = 1) {
  serial.println("pass");
   }
   else if (pass_fail = 0) {
  serial.println("fail");
   }
  delay(5000);
}


it seems no mater variable type set pass_fail to, serial output "pass" or both "pass" , "fail".  it's if statement runs first cause, or both. fyi, "if" statement not serial print rather other routines, tried simplify as possible try work. know missing minor detail, appreciated. thank you.

code: [select]
long resistance_array = 0; // sum of resistance measurements taken
this variable not array. phrase array not belong in it's name.

code: [select]
//**** things go wrong========
  if (pass_fail = 1) {

yep. = not same ==. 1 appropriate. 1 not.

code: [select]
if (resistance_reading >  resistance_min & resistance_reading <  resistance_max) {pass_fail = 1;} // pass if in spec
actually, started go wrong here. & , && different operators. pay attention use correct one.


Arduino Forum > Using Arduino > Programming Questions > "If" statement issue


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support