Hello! I am super new to coding and am trying to use an Arduino to move two servo motors. I have an error message:
"Compilation error: 'servo1Pin' does not name a type"
/private/var/folders/kk/phc3ywzj0bj30s9b3c4gh8xh0000gn/T/.arduinoIDE-unsaved202628-99380-vnrfmz.4x06/sketch_mar8a/sketch_mar8a.ino:13:1: error: 'servo1Pin' does not name a type"
servo1Pin.write(pos1);
^~~~~~~~~
/private/var/folders/kk/phc3ywzj0bj30s9b3c4gh8xh0000gn/T/.arduinoIDE-unsaved202628-99380-vnrfmz.4x06/sketch_mar8a/sketch_mar8a.ino:14:1: error: 'servo2Pin' does not name a type
servo2Pin.write(pos2);
^~~~~~~~~
/private/var/folders/kk/phc3ywzj0bj30s9b3c4gh8xh0000gn/T/.arduinoIDE-unsaved202628-99380-vnrfmz.4x06/sketch_mar8a/sketch_mar8a.ino:17:1: error: 'pos1' does not name a type
pos1 += 1;
^~~~
/private/var/folders/kk/phc3ywzj0bj30s9b3c4gh8xh0000gn/T/.arduinoIDE-unsaved202628-99380-vnrfmz.4x06/sketch_mar8a/sketch_mar8a.ino:18:1: error: expected unqualified-id before 'if'
if (pos1 > 180) {
^~
/private/var/folders/kk/phc3ywzj0bj30s9b3c4gh8xh0000gn/T/.arduinoIDE-unsaved202628-99380-vnrfmz.4x06/sketch_mar8a/sketch_mar8a.ino:21:1: error: expected unqualified-id before '{' token
{
^
exit status 1
Compilation error: 'servo1Pin' does not name a type
here is my code:
void loop() {
#include <Servo.h>
Servo Servo1;
int servo1Pin = 9;
int servo2Pin = 8;
}
int pos1 = 0;
int pos2 = 180;
//set servo position
servo1Pin.write(pos1);
servo2Pin.write(pos2);
//calculate next position
pos1 += 1;
if (pos1 > 180) {
pos1 = 0;
}
{
pos2 -= 1;
if (pos2 < 0) {
pos2 = 180;
}
delay(15);
}
