Hw to solve the problem about int val;

#include <Servo.h>

Servo x;
Servo y;
Servo grip;

int potpin = A0;
int val;
int potpin2 = A1;
int val;
val = 1
int potpin3  = A2;
int val;
val = 1

void setup() {
  servox.attach(2)
  servoy.attach(3)
  servogrip.attach(4)
  
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it for use with the servo (value between 0 and 180)
  Servox.write(val);                  // sets the servo position according to the scaled value
  delay(15); 

  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it for use with the servo (value between 0 and 180)
  Servoy.write(val);                  // sets the servo position according to the scaled value
  delay(15); 

  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it for use with the servo (value between 0 and 180)
  Servogrip.write(val);                  // sets the servo position according to the scaled value
  delay(15); 

}

Thanks for using code tags on your first post!

What is the problem?

Hint: lines like these must be in the loop() or setup() functions. Terminate the line with a semicolon.

val = 1

Correct these errors in the // comments

#include <Servo.h>

Servo x; // this should be servox
Servo y; // this should be servoy
Servo grip; // this should be servogrip

int potpin = A0;
int val;
int potpin2 = A1;
int val; // remove the re-definition of val
val = 1 // missing closing semi-colon
int potpin3  = A2;
int val; // remove the re-definition of val
val = 1 // remove the re-definition of val

void setup() {
  servox.attach(2) // missing the closing semi-colon
  servoy.attach(3) // missing the closing semi-colon
  servogrip.attach(4) // missing the closing semi-colon

}

void loop() {
  val = analogRead(potpin);
  val = map(val, 0, 1023, 0, 180);
  Servox.write(val); // lower-case "s" in servox
  delay(15);

  val = analogRead(potpin); // using the same pot as servox
  val = map(val, 0, 1023, 0, 180);
  Servoy.write(val); // lower case "s" in servoy
  delay(15);

  val = analogRead(potpin); // using the same pot as servox
  val = map(val, 0, 1023, 0, 180);
  Servogrip.write(val);  // lower case "s" in servogrip
  delay(15);
}

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