servo was not declared in this scope

i am making a 3 servo hexapod but when i upload the code i get the error: servo1 was not declared in this Scope. Can someone tell me what is wrong?

void setup() {
// put your setup code here, to run once:
#include <Servo.n>
Servo.n servo1;
servo1.attach(9);

#include <Servo.s>
Servo.s servo2;
servo2.attach(11);

#include <Servo.h>
Servo.h servo3;
servo3.attach(13);
}

void loop() {
// put your main code here, to run repeatedly:
servo1.write(20);
servo1.write(160);
}

I don't see it declared so yeah, the compiler is once again right :slight_smile: Have a look at a Servo example and spot the difference.

Also, please read How to use the forum next time before posting :slight_smile:

Where did you find Servo.n and Servo.s? I've never heard of them.

I have a feeling you're just quoting the last of many errors that were reported. Try the "Copy error messages" button and post ALL the errors.

Steve

void loop() {
  // put your main code here, to run repeatedly:
  servo1.write(20);
  servo1.write(160);
}

I suspect that after you get the use of the servo library figured out (look at the servo sweep example like septillian mentioned), you will want to allow some time between the 2 servo writes to give the servo time to move. Something like

void loop() {
  // put your main code here, to run repeatedly:
  servo1.write(20);
  delay(1000);
  servo1.write(160);
  delay(1000);
}

And another idea for you. Once you start appending variable names with numbers like you did for servo1, servo2 and servo3, it is time to read up about arrays.

I suspect that after you get the use of the servo library figured out, you'll want to sort out the concept of scope.

Objects declared inside a function, like setup, are not visible inside other functions, like loop.