Help with the following error

Hi, I am trying to write code and am very new to this. I have copied this from a sample but keep getting an error as in the picture. I cannot understand where to put the ;

Any help is very much appreciated.

Post the code and the error - don't post pictures.

Error reads as follows:
exit status 1
expected ‘;’ before ‘{’ token:

void loop() {

x = analogRead(joyH);
x = map(x, 0, 1023, 0, 180);

if (x > 100)
{servoVal1 = servoVal1 + 2;}
else if (x < 80)
{servoVal1 = servoVal1 - 2;}
else
{servoVal1 = servoVal1;}

myservo1.write{servoVal1);

y = analogRead(joyV);
y = map(y,0,1023,70,110);

if (y > 100)
{servoVal2 = servoVal2 + 2;}
else if (y<80)
{servoVal2 = servoVal2;}

myservo2.write(servoVal2);

delay(10);
}

Post the complete program and error, please.

Please post the COMPLETE code not just part of it. The error is often in the bit you didn't bother posting.

Steve

alanbarts:
myservo1.write{servoVal1);

Sorry, just starting out

C:\Users\sgste.DESKTOP-2UCEKQU\Documents\Technology\5. Arduino\JoyStick_controlled_Labyrinth\JoyStick_controlled_Labyrinth.ino: In function ‘void loop()’:

JoyStick_controlled_Labyrinth:37:17: error: expected ‘;’ before ‘{’ token

myservo1.write{servoVal1);

^

JoyStick_controlled_Labyrinth:50:1: error: invalid use of non-static member function

}

^

JoyStick_controlled_Labyrinth:50:1: error: expected ‘}’ at end of input

exit status 1
expected ‘;’ before ‘{’ token

#include <Servo.h>

const int servo1 = 1;
const int servo2 = 2;
const int joyH = 1;
const int joyV = 2;

int servoVal1;
int servoVal2;
int x;
int y;

Servo myservo1;
Servo myservo2;

void setup() {

servoVal1 = 110;
servoVal2 = 90;
myservo1.attach(servo1);
myservo2.attach(servo2);
}

void loop() {

x = analogRead(joyH);
x = map(x, 0, 1023, 0, 180);

if (x > 100)
{servoVal1 = servoVal1 + 2;}
else if (x < 80)
{servoVal1 = servoVal1 - 2;}
else
{servoVal1 = servoVal1;}

myservo1.write{servoVal1);

y = analogRead(joyV);
y = map(y,0,1023,70,110);

if (y > 100)
{servoVal2 = servoVal2 + 2;}
else if (y<80)
{servoVal2 = servoVal2;}

myservo2.write(servoVal2);

delay(10);
}

david_nc showed the issue in reply #5
Your error message also told you exactly where the problem is.
Put every { and } on a line by themselves and use ctrl+t in the IDE. That will format your code and the problem should jump right out at you.

Also, please use code tags when posting your code.

Thanks for the help, much appreciated. I have a lot to learn

Also, press in the IDE to format your code.

Placing
{
and
}
on a separate line makes things easier to read.

“I have a lot to learn”
So do we.

I have a lot to learn

Join the club, you can pay your dues here: :slight_smile:
https://www.arduino.cc/en/Main/Contribute