Error ServoTimer1:h

I got an error like this
25: error: ServoTimer1.h:No such file or directory using this example //Example code for using ServoTimer1 library
// hardware control of up to two servos, on Arduino pins 9 & 10

#include <ServoTimer1.h>

ServoTimer1 servo1;
ServoTimer1 servo2;

void setup()
{
pinMode(1,OUTPUT);
servo1.attach(9);
servo2.attach(10);
Serial.begin(19200);
Serial.print("Ready");
}

void loop()
{
static int v = 0;

if ( Serial.available()) {
char ch = Serial.read();

switch(ch) {
case '0'...'9':
v = v * 10 + ch - '0';
break;
case 's':
servo1.write(v);
v = 0;
break;
case 'w':
servo2.write(v);
v = 0;
break;
case 'd':
servo2.detach();
break;
case 'a':
servo2.attach(10);
break;
}
}
// Notice that no ServoTimer1::refresh() is needed.
}

from the software servo library

As an addition I'm using the arduino ATMEGA328 duemilanove.

why not use the Servo library distributed with arduino

replace
#include <ServoTimer1.h>
with
#include <Servo.h>

And change:
ServoTimer1 servo1;
ServoTimer1 servo2;
to
Servo servo1;
Servo servo2;

With the Arduino Servo library, you can use up to 12 servos, each servo can be connected to any unused pin.

Thanks a lot now I can upload it to the board.
Do you know any example that would run those two servos simultaneosly, because this isn't doing it.

you can add another case that writes to both servos:

   case 'b':
       servo1.write(v);
       servo2.write(v);
       v = 0;
       break;

Writing that gives me another Error error:expected`:'before 'sevo1'

In function 'void loop()':
error:expected`:'before 'sevo1'

Now i wrote : before the servo1 It shows no error but the servos aren't doing anything so what's the problem?

E: I checked that the servos are connected with the sweap example and it went well.

do the other commands work?

try sending the following commands
90s (send)
90w (send)
90b (send)

if that doesn't work, can you post your sketch (your code will be easier to read if you use a code block, select this using the # icon from the post menu)

I don't know where to write those commands, atleast if I make a sketch with 90s/w/b it doesn't work it gives me aqn error Invalid suffix "s" on integer constant, so here is my sketch.

#include <Servo.h>

Servo servo1;
Servo servo2;

void setup()
{
  pinMode(1,OUTPUT);
  servo1.attach(9);
  servo2.attach(8);
  Serial.begin(19200);
  Serial.print("Ready");
}

void loop()
{
  static int v = 0;

  if ( Serial.available()) {
    char ch = Serial.read();

    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(8);
        break;
      case 'b'
        :servo1.write(v);
      servo2.write(v);
      v = 0;
      break;
    }
  }
}

And why i have those commands on slots 8 and 9 is because those are the locations on my arduino digital slots.

the sketch you posted compiles without error for me.
What arduino version are you using? what operating system?

My arduino(Arduino duemilanove ATMEGA328) also loads it up, but the servos don't do anything.
I'm running windows 7.
Arduino 0018

it gives me aqn error Invalid suffix "s" on integer constant

My arduino(Arduino duemilanove ATMEGA328) also loads it up, but the servos don't do anything.

those say two different things, which is correct?

The second one is for the hole code, the first one came up after writing 90s and trying to upload

90s (send)
90w (send)
90b (send)

are the serial commands to send from the serial monitor. Did you try them? do any of them work. try sending other values:
20s (send) - send an angle of 20 to servo1
120w (send) - send an angle of 120 to servo2

note that you enter the servo angle followed by the letter indicating the servo to use in Serial Monitor and then press the (send) button

bear in mind that Serial Monitor defaults to 9600, why not set the value of serial.begin to 9600 and see if that fixes things.

Now those commands work after changing the value of serial.begin to 9600.
What does the code actually do?
Does it put the servos to 90 degrees?
If I tell you what my projekt is. I'm trying to make the two Servos run simultaneosly. so that they go from 0 to 180 degrees and from 180 degrees back to 0 like in the sweap example but with 2 Servos.
And to make it a bit more difficult, because i want to make a robot walk, I want the other one(8) to always be approximately 45 degrees ahead of the other (9=).
I hope you understood :-/

What does the code actually do?

Have another read of the servo reference to see what the servo commands do. The sketch gets values from the serial port and writes these to the servo.
You can add some serial.print statements if you would like to see how the value v is built up through each incoming serial character.

There are lots of ways to do your project.
The best one to use is the one you are most comfortable with.

Perhaps start with the sweep example and add in code so that both servos sweep together.

When you have this working you can think about how to change the value of pos for the second servo so it always has the offset you want.

But first, get two servos sweeping

Have fun!

Ok thanks a lot from your help I'll post again if/when I crash into more problems or just in the pure lack of information. :slight_smile:

Got that working
[code#include <Servo.h>

Servo myservo;
Servo mysecondservo;// create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0;// variable to store the servo position

void setup()
{
mysecondservo.attach(8);
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+45);
mysecondservo.write(pos); // tell servo to go to position in variable 'pos'
delay(35); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos+45); // tell servo to go to position in variable 'pos'
mysecondservo.write(pos);
delay(30); // waits 15ms for the servo to reach the position
}
}

[/code]
But the problem now is that the servo is running 45 degrees before the secondservo(like supposed to) but when reaching it's destination It stops and waits for the secondservo and when the secondservo gets there it immediately starts moving towards 0 degrees again and when it has advanced 45 degrees the servo also starts moving again and when the secondservo reaches 0 degrees the same time when the servo reaches 45 degrees they both start moving towards 180 degrees again, and this follows the hole time.(as supposed to) The actual problem is that the both servos should be moving all the time, But only one is doing it.

one way to do this is to use the modulo operator (the % symbol) a google search should provide more info on this

I suggest you add some serial print statments to see what values are produced. Here is a code fragment you can insert into your sketch:
int value = (pos+45) % 180;
Serial.print(pos);
Serial.print((",")
Serial.println(value);
myservo.write( value);

Where should I add that code?
How can mathematical formulas be added to the code?
I needed to add a formula like this to make it run smooth like sin.

60sin(2pi/100*x+pi/2)+60

I managed to do that and now the otherone is moving correctly from 45 degrees to 135 degrees, but the otherone is moving from 90 degrees to 180 degrees, which makes the robot fall down. So after testing it with the robot i now have found out that the servos should be both going from 45degrees to 135 degrees but not at the same time but so that they are in 90 degrees at the same time and when myservo reaches 135degrees mysecondservo should reach 45 degrees and they should both start to move towards the other end again(myservo<45;mysecondservo<135)

Is it possible to do it that way?