IF query construction - resolved

I need to ask here in the condition of the digital output is already set to high. It is perhaps this design?

.....
digitalWrite (2, HIGH);
if (digitalWrite (2) == LOW) {client.print ("OFF");} else {clint.print ("ON";}
....
Is it fair condition digitalWrite (2) == LOW or need to ask me otherwise? thank you

You need to do a Read instead og Write

But digital output 2 I declared as output I looked at him then inquire as to the input?

I have a handy little Output class that wraps the digital IO in some useful functions. It also keeps track of the current state of the output pin, and allows callbacks when a pin changes state.

Output myPin(4);

void setup() {
  myPin.begin();
}

void loop() {
  myPin.high();
  if (myPin.getState() == HIGH) {
    // Do something
  }
}

Or, with a callback:

Output myPin(4);

void setup() {
  myPin.begin();
  myPin.onHigh(doSomething);
}

void loop() {
  myPin.high();
}

void doSomething(uint8_t level) {
  // Do something (level == HIGH)
}

Thank you very much for solving the problem. :slight_smile: