If condition related to servo position

Is there any way of making an if() statement that includes as a variable a servo position?
I've been trying to activate another part of my project only when my servo is at 180 degrees, however, an error pops up "Compilation error: could not convert 'servoMotor.Servo::write(180)' from 'void' to 'bool'".
I know there is a mistake because of the variable type, but I don't know how to correct it.

This is the code

  if(light <60 && servoMotor.write(180)){

  }

Thanks in advance for the help!

servoMotor.write doesn't return anything ... perhaps you meant servoMotor.read() ?

if(light < 60 && servoMotor.read() == 180){

That makes much more sense, however it still doesn't work :smiling_face_with_tear:
Any other idea? (Still, Thx)

Perhaps a bit more context, like a complete sketch where this is used.

I would also suggest printing out the value that servo.read() is returning.

Looking only at one statement makes it impossible to see what it is that isn't working and how it isn't. Working.

a7

It appears to be a continuation of this project: Servo motor won't go back to 0 degrees

No need to start an entirely new thread

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