Hello, I'm trying to create a project that would involve using the distance module (HC-SRO4) as well as a speaker to generate sound. However, I run into some trouble when compiling whenever I try to use both at once. It will give me this error:
core.a(Tone.cpp.o): In function __vector_7': C:\Users\Drew\Desktop\arduino-1.0.4\hardware\arduino\cores\arduino/Tone.cpp:535: multiple definition of
__vector_7'
NewPing\NewPing.cpp.o:C:\Users\Drew\Desktop\arduino-1.0.4\libraries\NewPing/NewPing.cpp:214: first defined here
If I have only the code for the distance module, it compiles fine. If I have only the code for generating tone, it compiles fine. But when ! try to combine the two it won't let me. Does anybody know why this may be?
I think it means that both libraries are trying to use the same interrupt. When I look in the datasheet "Vector Number 7" is the watchdog timer vector. Maybe it means the vector at address 7. That would be the Timer 2 Compare Register A interrupt. That makes more sense.
I guess the two libraries are not compatible.
The rangefinder really doesn't need a library. This code is from my book 'Hacking Electronics' p 155.
// range_finder_budget
// Arduino Uno or Leonardo
int trigPin = 9;
int echoPin = 10;
int gndPin = 11;
int plusPin = 8;
int lastDistance = 0;
void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(gndPin, OUTPUT);
digitalWrite(gndPin, LOW);
pinMode(plusPin, OUTPUT);
digitalWrite(plusPin, HIGH);
}
void loop()
{
Serial.println(takeSounding_in());
delay(500);
}
int takeSounding_cm()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
int duration = pulseIn(echoPin, HIGH);
int distance = duration / 29 / 2;
if (distance > 500)
{
return lastDistance;
}
else
{
lastDistance = distance;
return distance;
}
}
int takeSounding_in()
{
return takeSounding_cm() * 2 / 5;
}