2

I have a problem with Servo library. This is my (very short XD) "code":

#include <Servo.h>
void setup() {
 Servo.attach(9, 554, 2400);
}
void loop() {
 Servo.write(2000);
}

And it returns:

Arduino:1.6.5 (Windows 7), Board:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
sketch_aug24a.ino: In function 'void setup()':
sketch_aug24a:4: error: expected unqualified-id before '.' token
sketch_aug24a.ino: In function 'void loop()':
sketch_aug24a:8: error: expected unqualified-id before '.' token
expected unqualified-id before '.' token

Like there is no included library. What can I do with it ?

Peter Bloomfield
11k9 gold badges48 silver badges87 bronze badges
asked Aug 24, 2015 at 11:12

1 Answer 1

2

Servo is a class not an object. You have to instantiate it, and then call the functions on the instance. For example:

#include <Servo.h>
Servo sv;
void setup() {
 sv.attach(9, 554, 2400);
}
void loop() {
 sv.write(2000);
}

(Unlike some other libraries, it's done this way so that you can use more than one servo at the same time. You'd make one instance for each servo you want to control.)

answered Aug 24, 2015 at 11:15
2
  • Oh, I get it :o Clever! Commented Aug 24, 2015 at 11:19
  • But I think, my servo is broken ;_;, dammit xd Commented Aug 24, 2015 at 11:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.