Help with error

My friend wrote this sample program to test some of the aspects of our electronics project but he keeps getting an error when compiling. The problem appears to be with the use of two libraries at once.

#include <Servo.h>
#include <Tone.h>
Tone tone1;

int doorOpen = 0;        //assign that door is closed
int pbno = 2;            //the push button is on pin 2
int mat = 3;              //the mat is on pin 3
int greenLed = 4;        //open light is on pin 4
int redLed = 5;            //close light is on pin 5

Servo myservo;              // 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() 
{ 
  tone1.begin(6);                    //sets the speaker for pin 6
  myservo.attach(7);                    // attaches the servo on pin 7 to the servo object 
  pinMode(pbno, INPUT);                  //push button set to input
  pinMode(mat, INPUT);                    // Pad sensor set to input
  pinMode(greenLed,  OUTPUT);                 // Door opening audio alert
  pinMode(redLed,  OUTPUT);                // Door closing audio alert

} 

void loop() 
{ 
  if (digitalRead (pbno) == HIGH)  
  {
    digitalWrite(greenLed, HIGH);
    tone1.play(NOTE_G6);delay(500);        //plays opening door sound
    tone1.play(NOTE_C7);delay(500);
    tone1.play(NOTE_C6);delay(750);
    tone1.stop();
    for(pos = 0; pos < 90; 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 
      }
    }
  }

Here’s the error:

C:\DOCUME~1\20028283\LOCALS~1\Temp\build15368.tmp\Tone\Tone.cpp.o: In function `__vector_11’:

C:\Documents and Settings\20028283\Desktop\ARDUINO STUFF\arduino-0017\hardware\libraries\Tone/Tone.cpp:438: multiple definition of `__vector_11’

C:\DOCUME~1\20028283\LOCALS~1\Temp\build15368.tmp\Servo\Servo.cpp.o:C:\Documents and Settings\20028283\Desktop\ARDUINO STUFF\arduino-0017\hardware\libraries\Servo/Servo.cpp:104: first defined here

As far as I know there shouldn’t be a problem with using two libraries at once…

We'd need to know what kind of board you have (Mega, Pro, Mini, Duemilanve, etc.) as well as whether or not you selected the correct board in the Tools menu.

We're using a Duemilanove with the Atmega328, and the correct board is selected.

I've verified that the issue is not with the code itself, as I've since written my own program that works fine, if I add the Servo library by itself it still works fine, if I add the Tone library by itself it still works fine. With both libraries at the same time I get the same error as above.

Vector 11 is one of the timer interrupts. It looks like both libraries are trying to use the same timer. Unfortunately there's probably not a lot you can do about it.

I think the problem only occurs when using Tone with Servo, perhaps we will have to use a stepper motor…

Are you sure there is no way to fix this? It’s a fairly big inconvenience to not be able to use the Tone library with the Servo library. For our project we wish to have an audio alert accompany the motor operation.

StaticChu, if you use the tone function built into Arduino release 0018 it will work with the servo library.

see: http://arduino.cc/en/Reference/Tone

Thanks everyone for the help and the quick responses. We're using the 0017 build so I'll update now and if you're right it should work.

if you're right it should work.

somethimes things don't work even when your right :wink:

But I have run tone library with lots of servos connected without problem.

Have fun