Can't get a Servo to Stop Moving

I've been lurking for a while to get help on my code, and I've seen people with the same problem as mine, but no matter what I do I can't get my Servo to stop travelling 180 degrees. Currently I have a boolean 0/1 expression to tell the code when it's allowed to move the servo, but it's still not working. I just need it to move 180 under one condition, and move -180 under another and then hold until the next condition is met. It sits still under the first IF statement, but not under the second.
The buzzing noise of the Servo is driving me nuts!


if (c == 0)
{
if( temperature >= 28 );
{
pos = -180;

myServo.write(pos);
c = 1;
delay(1000);
}
}

if(c == 1 )
{
if ( temperature <= 27 )
{
pos = 180;

myServo.write(pos);
c = 0;
delay (1000);
}

FYI, you will probably cop flak for not posting the whole code and not including code tags and not including info about the type of servo you're using.

Does it have physical end stops? If so, have you tried slightly lower angles?
The last time I had a similar problem to what you're describing, the servo was hitting the physical stop before reaching the desired angle so it was trying to drive itself constantly. Reducing it 5-10° stopped the constant noise in that case.

You might also want to note that servo.write() takes values from 0 to 180. So write(-180) is simply wrong. I think the servo library protects you by interpreting it as write(0) but I haven't checked.

Steve

On a circle, 180 degrees is the same position as -180 degrees.

Perhaps you mean 90 and -90? Be aware that most 180 degree servos can only move 150-160 degrees.

if( temperature >= 28 );oops

Please remember to use code tags when posting code.