I'm writing the code in VS Code on IO Platform. Yesterday i finished my code and uploaded it to the Arduino Uno. It works fine. Next day i launched the VS Code and i changed the code a bit, then i uploaded it and i got the error.
Error:
Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1
I am using the libary NewPing.h
. The code should does this: If is distance more than 20cm, the the buzz makes the sound and turns on the red led. If distance is less than 20cm, the blue led turns on
The code:
#include <Arduino.h> //It has to be there, because the arduino ide in VS Code will not work.
#include <NewPing.h>
#define echo_pin 3
#define trig_pin 4
#define max_range 450
#define red_led_pin 7
#define blue_led_pin 9
#define buzz_pin 10
int distance = 0;
NewPing sonar(trig_pin, echo_pin, max_range);
void setup(){
Serial.begin(9600);
pinMode(red_led_pin, OUTPUT);
pinMode(blue_led_pin, OUTPUT);
pinMode(buzz_pin, OUTPUT);
}
void loop() {
distance = sonar.ping_cm();
delay(50);
if (distance > 0) {
distance = 0;
for (int i=0; i<5; i++) {
distance += sonar.ping_cm();
delay(50);
}
distance /= 4;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
if (distance > 20) {
digitalWrite(blue_led_pin, LOW);
digitalWrite(red_led_pin, HIGH);
tone(buzz_pin, 1500);
tone(buzz_pin, 800);
}
else {
digitalWrite(red_led_pin, LOW);
digitalWrite(blue_led_pin, HIGH);
}
}
}
I don't undersand, what has changed. I tried to import again the libary https://www.arduino.cc/en/guide/libraries by importing the *.zip file, also installing in IDE.
#define ENABLE_TIMER_BASED_PING 1
commented out or active?