Hi,
I am using both the NewPing library and tone command in the same code. When I try to compile the code for a Mega, it comes up with this error which leads me to believe that _vector_13 is defined twice. How would I go about fixing this error if possible?
Arduino: 1.8.5 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_13'
libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
This is a simplified version of the code I am using for a robot that plays 8 random notes before it corrects itself.
#include <NewPing.h>
#include "pitches.h"
int randome[] = {NOTE_A4, NOTE_B4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A5, NOTE_B5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A3, NOTE_B3,};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {10};
int num = sizeof(randome) / sizeof(randome[0]);
int tonePin = 10;
void play() {
randomSeed(analogRead(0));
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations[0]; //change 0 --> thisNote to make note length case specific
tone(tonePin, randome[random(0 - (num - 1))], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(tonePin); // stop the tone playing:
}
}
void setup(){
play();
}
void loop(){
}