Did you define and instantiate a servo object like
Servo myServo1:?
What does this mean?
Have you looked at a servo example to see how your code differs?
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
a Servo object (variable) needs to be defined before it is used. it needs to be configured (attached) for a specific pin (i.e. 10)
Servo servo;
void setup() {
servo.attach(10);
}
an RC servo is controlled by a pulse from 1-2 msec which corresponds to an angle. it's not a binary value on/off, HIGH/LOW. the write() function will generate the pulse for a specific angle
consdier
#include <Servo.h>
const byte ServoPin = 10;
Servo servo;
void setup()
{
// put your setup code here, to run once:
servo.attach(ServoPin);
}
void loop()
{
// put your main code here, to run repeatedly:
servo.writeMicroseconds(1500);
}
or
const byte ServoPin = 10;
void setup()
{
// put your setup code here, to run once:
pinMode(ServoPin, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(ServoPin, HIGH)
delayMicroseconds(1500);
digitalWrite(ServoPin, LOW);
delay(20); // Keep the repeat rate near 50 Hz
}
Either will move the servo to a middle position and keep it there forever. Once you assign a pin to the Servo library you should not write to it directly.