// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------
#include <NewPing.h>
#include <Tone.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
Tone tone1;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
tone1.begin(13);
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
unsigned int Value = (uS / US_ROUNDTRIP_CM);
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
Serial.println("cm");
if (Value <= 10)
{
tone1.play(NOTE_CS4);
}
}
but when I upload it gives the error message:
" Tone\Tone.cpp.o: In function __vector_7': D:\Documents\arduino-1.0.1-windows\arduino-1.0.1\libraries\Tone/Tone.cpp:439: multiple definition of __vector_7'
NewPing\NewPing.cpp.o:D:\Documents\arduino-1.0.1-windows\arduino-1.0.1\libraries\NewPing/NewPing.cpp:214: first defined here "
What does this mean? and how can I fix this?
Thanks!
I think it means you tried to combine two libraries (Tone and NewPing) and they both want to use the same interrupt. I don't know, I don't use those libraries.
so, yeah I thought something as well.. because the error says ' multiple definitions'
But I've got no idea which ones.. I look into both libraries, but couldn't find anything where they use or define the same thing
class NewPing {
public:
NewPing(uint8_t trigger_pin, uint8_t echo_pin, int max_cm_distance = MAX_SENSOR_DISTANCE);
unsigned int ping();
unsigned int ping_in();
unsigned int ping_cm();
unsigned int ping_median(uint8_t it = 5);
unsigned int convert_in(unsigned int echoTime);
unsigned int convert_cm(unsigned int echoTime);
void ping_timer(void (*userFunc)(void));
boolean check_timer();
unsigned long ping_result;
static void timer_us(unsigned int frequency, void (*userFunc)(void));
static void timer_ms(unsigned long frequency, void (*userFunc)(void));
static void timer_stop();
so they both use the uint8_t
what can I change and how?
It would be awesome if someone could help me.
what can I change and how?
It would be awesome if someone could help me.
uint8_t is just a variable type description, one can use that as many times and in as many included libraries as one wants. It would be like saying there is a conflict because two functions both use integer variables. The conflict must be elsewhere.
But...the problem goes much deeper than that. If they're both using the same interrupt for something they're probably using the same hardware timer as well. Sharing a hardware resource might not be something you can work around.
mcremers:
hmm right.. I can't find anything which is in the 2 libraries the same and isn't meant to..
I think you will have to look at the .cpp files in the tone and ping libraries where the actual code is for any conflicts. *.h files are mostly just to declare variables, functions, and methods used for the library.
I think you will have to look at the .cpp files in the tone and ping libraries where the actual code is for any conflicts. *.h files are mostly just to declare variables, functions, and methods used for the library.
thanks lefty, I was indeed searching into the .h files
I've found the problem in the .cpp files
it's going to be something like this:
ISR(...)
{
}
But...the problem goes much deeper than that. If they're both using the same interrupt for something they're probably using the same hardware timer as well. Sharing a hardware resource might not be something you can work around.
So, yes. they both use the same interrupt.
ISR(TIMER5_COMPA_vect) { .....
Which means I'm probably not able to work with these 2 libraries together? That would be a pity
But I thank you all for your helps and thoughts guys! appreciate it.