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
1 Answer 1
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
lang-cpp