newTone and Servo problem !!!

Hi everyone I am creating a project with an ultrasonic sensor and a servo motor, only in my code putting both newTone.h and servo.h as libraries they conflict so they cannot start the code. I need help what can I do? it is quite urgent

This is the code:

#include <NewPing.h>
#include <NewTone.h>
#include <Servo.h>

#define PIN_TRIG 2
#define PIN_ECHO 3
#define PIN_BUZZ 9
#define MAX_DIST 10

NewPing detector(PIN_TRIG, PIN_ECHO, MAX_DIST);

int mal;
Servo mio;

void setup()

{

Serial.begin(9600);

{

mio.attach(8);

}

}

void loop()

{

//delay(500);
unsigned int uS = detector.ping();
Serial.print(“Dista: “);
int cm = detector.convert_cm(uS);
Serial.print(cm);
Serial.println(” cm”);
if(cm > 0)

{

int durationSound = 1000/8;
NewTone(PIN_BUZZ,200,durataSuono);
int pause = durationSound * 1.30;
delay(pause);
noNewTone(PIN_BUZZ);

for (mal = 0; mal < 180; mal++)
{

Serial.println(mal);
mio.write(mal);
delay(13);

}

for (mal = 179; mal > -1; mal–)

{

Serial.println(mal);
io.write(mal);
delay(13);

}

}

}

The error code is this:

libraries\NewTone\NewTone.cpp.o (symbol from plugin): In function NewTone(unsigned char, unsigned long, unsigned long)': (.text+0x0): multiple definition of __vector_11’
libraries\Servo\avr\Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for the Arduino Uno board.

I apologize if I can not put the code well but I hope it is now more understandable.

Please edit your post to show your sketch within </> code-tags and remove any excess white lines. Also include the error message (within </> code-tags) As a small note : naming variables in your native tongue makes sense, but it does confuse matters a little for the dominantly English speaking community (iow those variable names do not have a lot of meaning to me … ok they have some, but i do encourage people to use english variable names it helps.)

it is quite urgent

Not to me it's not.

pronotch02:
Now it’s better?

Deva_Rishi:
Please edit your post to show your sketch within </> code-tags and remove any excess white lines. Also include the error message (within </> code-tags) As a small note : naming variables in your native tongue makes sense, but it does confuse matters a little for the dominantly English speaking community (iow those variable names do not have a lot of meaning to me … ok they have some, but i do encourage people to use english variable names it helps.)

within </> code-tags

It can’t be that hard. It is better to do so, so this : mio.attach(8); doesn’t look like a smiley

(.text+0x0): multiple definition of `__vector_11'

That means the same interrupt vector is use by both libraries, which stems from the use of the same timer. In effect that means that these libraries are not compatible. You can try ServoTimer2 instead of servo.h, if that also doesn’t work you can opt to send the pulse to the servo manually.

okay thanks. But since the library still gives me problems how can I send the signal to the servo manually?

If you send a 'HIGH' pulse with a duration between 500us and 2500us with about a 20ms interval you can control the servo. Have a look at Servo.h & Servo.cpp for more exact numbers and angle to pulse length calculations. The interval between pulses needs to be at least 20ms but can be a fair bit more if required. (up to 100ms is usually ok as well)