Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.)

share|improve this answer
    
Oh, I get it :o Clever! –  Nicolas Aug 24 at 11:19
    
But I think, my servo is broken ;_;, dammit xd –  Nicolas Aug 24 at 11:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.