Can't find the "expected ';' before '{' token" in my code

Hi everyone,

I'm new to arduino and I'm trying to make a robotic arm.
I get this error and I just can't find the problem.

exit status 1
expected ';' before '{' token
#include <Servo.h>

const int xAs1 = A0;
const int yAs1 = A1;
const int xAs2 = A2;
const int yAs2 = A3;

int positionxAs1 = 0;
int positionyAs1 = 0;
int positionxAs2 = 0;
int positionyAs2 = 0;

int servoValue1 = 90;
int servoValue2 = 90;
int servoValue3 = 90;

Servo servo1;
Servo servo2;
Servo servo3;

void setup() {
  pinMode(xAs1, INPUT);
  pinMode(yAs1, INPUT);
  pinMode(xAs2, INPUT);
  pinMode(yAs2, INPUT);
  pinMode(9, OUTPUT);
  servo1.attach(5);
  servo1.write(servoValue1);
  servo2.attach(6);
  servo2.write(servoValue2);
  servo3.attach(3);
  servo3.write(servoValue3);
}

void loop() {
  servoValue1 = map(positionyAs1, 0, 1023, 0, 180);
  servoValue2 = map(positionyAs2, 0, 1023, 0, 180);
  servoValue3 = map(positionxAs2, 0, 1023, 0, 180);

  dcMotorValue(xAs1);
  sensorReading1(yAs1);
  sensorReading2(xAs2);
  sensorReading3(yAs2);
  delay(100);
}
void dcMotorValue(int Position) {
  positionxAs1 = analogRead(xAs1);
  if (Position >= 400 && Position <= 620) {
    digitalWrite (9, LOW);
  }
  else ((Position >=0 && Position <= 399) || (Position >= 621 && Position <= 1023)) {
    digitalWrite (9, HIGH);
  }
}
void sensorReading1(const int Position) {
  positionyAs1 = analogRead(yAs1);
  if (Position >= 500 && Position <= 520) {
    digitalWrite (servoValue1);
  }
  else ((Position >= 450 && Position <= 499) || (Position >= 521 && Position <= 570)) {
    digitalWrite (servoValue + 1);
  }
  else ((Position >= 400 && Position <= 449) || (Position >= 571 && Position <= 620)) {
    digitalWrite (servoValue1 + 2);
  }
  else ((Position >= 350 && Position <= 399) || (Position >= 621 && Position <= 670)) {
    digitalWrite (servoValue1 + 3);
  }
  else ((Position >= 300 && Position <= 349) || (Position >= 671 && Position <= 720)) {
    digitalWrite (servoValue1 + 4);
  }
  else ((Position >= 250 && Position <= 299) || (Position >= 721 && Position <= 770)) {
    digitalWrite (servoValue1 + 5);
  }
  else ((Position >= 200 && Position <= 249) || (Position >= 771 && Position <= 820)) {
    digitalWrite (servoValue1 + 6);
  }
  else ((Position >= 150 && Position <= 199) || (Position >= 821 && Position <= 870)) {
    digitalWrite (servoValue1 + 7);
  }
  else ((Position >= 100 && Position <= 149) || (Position >= 871 && Position <= 920)) {
    digitalWrite (servoValue1 + 8);
  }
  else ((Position >= 50 && Position <= 99) || (Position >= 921 && Position <= 970)) {
    digitalWrite (servoValue1 + 9);
  }
  else ((Position >= 0 && Position <= 49) || (Position >= 971 && Position <= 1023)) {
    digitalWrite (servoValue1 + 10);
  }
}
void sensorReading2(const int Position) {
  positionxAs2 = analogRead(xAs2);
  if (Position >= 500 && Position <= 520) {
    digitalWrite (servoValue2);
  }
  else ((Position >= 450 && Position <= 499) || (Position >= 521 && Position <= 570)) {
    digitalWrite (servoValue2 + 1);
  }
  else ((Position >= 400 && Position <= 449) || (Position >= 571 && Position <= 620)) {
    digitalWrite (servoValue2 + 2);
  }
  else ((Position >= 350 && Position <= 399) || (Position >= 621 && Position <= 670)) {
    digitalWrite (servoValue2 + 3);
  }
  else ((Position >= 300 && Position <= 349) || (Position >= 671 && Position <= 720)) {
    digitalWrite (servoValue2 + 4);
  }
  else ((Position >= 250 && Position <= 299) || (Position >= 721 && Position <= 770)) {
    digitalWrite (servoValue2 + 5);
  }
  else ((Position >= 200 && Position <= 249) || (Position >= 771 && Position <= 820)) {
    digitalWrite (servoValue2 + 6);
  }
  else ((Position >= 150 && Position <= 199) || (Position >= 821 && Position <= 870)) {
    digitalWrite (servoValue2 + 7);
  }
  else ((Position >= 100 && Position <= 149) || (Position >= 871 && Position <= 920)) {
    digitalWrite (servoValue2 + 8);
  }
  else ((Position >= 50 && Position <= 99) || (Position >= 921 && Position <= 970)) {
    digitalWrite (servoValue2 + 9);
  }
  else ((Position >= 0 && Position <= 49) || (Position >= 971 && Position <= 1023)) {
    digitalWrite (servoValue2 + 10);
  }
}
void sensorReading3(const int Position) {
  positionyAs2 = analogRead(yAs2);
  if (Position >= 500 && Position <= 520) {
    digitalWrite (servoValue3);
  }
  else ((Position >= 450 && Position <= 499) || (Position >= 521 && Position <= 570)) {
    digitalWrite (servoValue3 + 1);
  }
  else ((Position >= 400 && Position <= 449) || (Position >= 571 && Position <= 620)) {
    digitalWrite (servoValue3 + 2);
  }
  else ((Position >= 350 && Position <= 399) || (Position >= 621 && Position <= 670)) {
    digitalWrite (servoValue3 + 3);
  }
  else ((Position >= 300 && Position <= 349) || (Position >= 671 && Position <= 720)) {
    digitalWrite (servoValue3 + 4);
  }
  else ((Position >= 250 && Position <= 299) || (Position >= 721 && Position <= 770)) {
    digitalWrite (servoValue3 + 5);
  }
  else ((Position >= 200 && Position <= 249) || (Position >= 771 && Position <= 820)) {
    digitalWrite (servoValue3 + 6);
  }
  else ((Position >= 150 && Position <= 199) || (Position >= 821 && Position <= 870)) {
    digitalWrite (servoValue3 + 7);
  }
  else ((Position >= 100 && Position <= 149) || (Position >= 871 && Position <= 920)) {
    digitalWrite (servoValue3 + 8);
  }
  else ((Position >= 50 && Position <= 99) || (Position >= 921 && Position <= 970)) {
    digitalWrite (servoValue3 + 9);
  }
  else ((Position >= 0 && Position <= 49) || (Position >= 971 && Position <= 1023)) {
    digitalWrite (servoValue3 + 10);
  }
}

You need to post your program as a single piece because errors can creep in when I try to join the bits - and I can't be sure if you have omitted something or not.

The error message will have listed the line where the compiler got stuck. The problem will be on one of the lines before that. Presumably you forgot to terminate a line with a semi-colon.

...R

Whaaaaaaaaaaaaaa, why couldn't you just post the whole code and the whole error message. Now we have to stitch the code back together (which I'm not going to do) and you deleted an impotent part of the error message namely the line numbers...

@Robin2 @septillion sorry for this. I've changed all the else statements to else if statements and now I do not get the error anymore.

Have you noticed that your sensor2 function has a lot of repeated code?

void sensorReading2(const int Position) {
  // not sure why you red this value here when you don't use it here, but meh
  positionxAs2 = analogRead(xAs2);

  // not sure why you are not passing a pin number to digitalWrite, but meh

  if(position < 500)
    digitalWrite (servoValue2 + (500-Position)/50 + 1);
  else if(position >= 520)
    digitalWrite (servoValue2 + (Position-520)/50 + 1);
  else
    digitalWrite (servoValue2);
}

alternatively, this will not do exactly the same as your code at the edge cases where position < 510, but it's pretty close:

    digitalWrite (servoValue2 + (abs(position-510) + 40) / 50);