Servo Position based on a value

Hi, i am trying to get my adruino uno to be in one of three positions based on the comparison between two number, one if they are equal the other if the first number is bigger and the final if the second is bigger. So far i have used an if statement with a each different condition, and then i have used myservo.write() to move the servo, i have used 0,90 and 180 as the positions it will work for a little but but then it just seems to break down and doesnt work as i believe the code should, any help would be appreciated.

My code: if(playerOneScore == playerTwoScore) { myservo.write(pos); } else if(playerOneScore > playerTwoScore) { myservo.write(180); } else (playerTwoScore > playerOneScore) { myservo.write(0); }

Read the stickies about how to use the forum.

Post properly formatted code between code tags, please. Like this. Upper left above the emoticons </>.

if(playerOneScore == playerTwoScore)
{
    myservo.write(pos);
}
else if(playerOneScore > playerTwoScore)
{
    myservo.write(180);
}
else (playerTwoScore > playerOneScore)
{
    myservo.write(0);
}

Post the entire sketch. We have no idea what else is going on in the rest of the sketch and the problem is probably somewhere outside of the snippet you posted.

Are you using Strings? How are the servos powered?

seems to break down and doesn’t work as i believe the code should,

Is not very descriptive. If you take your car to the shop, do you just say “It doesn’t work”?

lbeza: if(playerOneScore == playerTwoScore) {    myservo.write(pos);    } else if(playerOneScore > playerTwoScore) {    myservo.write(180);    } else (playerTwoScore > playerOneScore) {    myservo.write(0);   }

The else clause should NOT contain a boolean expression. Try:

if(playerOneScore == playerTwoScore) {
    myservo.write(pos);
    } else if(playerOneScore > playerTwoScore) {
    myservo.write(180);  
  } else { // (playerTwoScore > playerOneScore)
    myservo.write(0);
   }

I'm surprised your sketch compiled without error.

 } else (playerTwoScore > playerOneScore) {

If the scores are not equal, and player two doesn't have a higher score that player one, there isn't a hope in hell that this statement would NOT evaluate to true, if you hadn't left the if out. Therefore, the test is useless.

As I suspected, he original version won’t compile:

#include <Servo.h>
Servo myservo;
int pos = 90;
int playerOneScore, playerTwoScore;

void setup() {
  myservo.attach(9);
/////////////////////////////////////////
if(playerOneScore == playerTwoScore)
{
    myservo.write(pos);
}
else if(playerOneScore > playerTwoScore)
{
    myservo.write(180);
}
else (playerTwoScore > playerOneScore)
{
    myservo.write(0);
}
/////////////////////////////////////////
}
void loop() {}
sketch_oct29b.ino: In function 'void setup()':
sketch_oct29b:18: error: expected ';' before '{' token
expected ';' before '{' token