Trying to compile this sketch, I get the errors shown. I have other sketches with the same code for using a servo and they compile correctly. Please advise what is wrong here.
Dale Gloer
type or paste code here
```cpp
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 90); // scale it for use with the servo (value between 0 and 90)
Serial.println(val);
myservo.write(val); // sets the servo position according to the scaled value
delay(100); // waits for the servo to get there
}
+++++++++++++ error messages +++++++++++
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino:3:8: error: redefinition of 'Servo myservo'
Servo myservo; // create servo object to control a servo
^~~~~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch.ino:4:7: note: 'Servo myservo' previously declared here
Servo myservo; // create servo object to control a servo
^~~~~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino:5:5: error: redefinition of 'int potpin'
int potpin = A0; // analog pin used to connect the potentiometer
^~~~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch.ino:6:5: note: 'int potpin' previously defined here
int potpin = A0; // analog pin used to connect the potentiometer
^~~~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino:6:5: error: redefinition of 'int val'
int val; // variable to read the value from the analog pin
^~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch.ino:7:5: note: 'int val' previously declared here
int val; // variable to read the value from the analog pin
^~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino: In function 'void setup()':
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino:8:6: error: redefinition of 'void setup()'
void setup() {
^~~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch.ino:9:6: note: 'void setup()' previously defined here
void setup() {
^~~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino: In function 'void loop()':
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch_reversable.ino:13:6: error: redefinition of 'void loop()'
void loop() {
^~~~
D:\Files\3D prints\Road Chain\starter kit\arduino\rcs_arduino_sketch\rcs_arduino_sketch.ino:14:6: note: 'void loop()' previously defined here
void loop() {
^~~~
exit status 1
Compilation error: redefinition of 'Servo myservo'