Dht11 sensor reading

do {
live = (unsigned long)(micros() - startTime);
if ( live > 90 ) {
Serial.println("ERROR_TIMEOUT");
return;
}
}
while ( digitalRead(dht11_pin) == (i&1) ?HIGH : LOW );
//I want to know the meaning of this line (while ( digitalRead(dht11_pin) == (i&1) ?HIGH : LOW );).specially ((i&1)?HIGH:LOW)

You mean the ? : part? Search for "ternary operator c++"

1 Like

Thank you very much. I found the meaning searching "ternary operator c++"

Please, post the meaning with an example of your own.

(i&1)?HIGH:LOW is a bit like doing something like this:

int determineState(i) {
  int state;
  if (i&1 == true) {
    state = HIGH;
  }
  else {
    state = LOW;
  }
return state;

and then using it in the while loop like this:

while (digitalRead(dht11_pin) == determineState(i))

The ternary form makes it more compact.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.