Go Down

Topic: tone() equivalent or a way to recreate the function myself (Read 70 times) previous topic - next topic

SnipaSenpai

So for my project I have the annoying problem that I need to use the function tone() for a small speaker, but because I am also using the NewPing library for 5 HC-SR04 ultrasonic sensors there is some sort of of cross referencing between those 2 "libraries".

error :
Code: [Select]


Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

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

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.



If I delete every piece of code related to NewPing(or tone() ) it compiles without any errors.

So my questions are:
Is there a way to use tone() or is there a similar function?
Could I manually write a similar function or edit tone() somehow?

cattledog

Quote
there is some sort of of cross referencing between those 2 "libraries".
Yes, both use Timer2.

The alternatives to tone() to resolve the Timer2 conflict with NewPing are covered here.

https://bitbucket.org/teckel12/arduino-new-ping/wiki/Multiple%20Definition%20of%20%22__vector_7%22%20Error

NewTone uses Timer1, and is not a bad choice
https://bitbucket.org/teckel12/arduino-new-tone/wiki/Home

SnipaSenpai

Quote
Yes, both use Timer2.

The alternatives to tone() to resolve the Timer2 conflict with NewPing are covered here.

https://bitbucket.org/teckel12/arduino-new-ping/wiki/Multiple%20Definition%20of%20%22__vector_7%22%20Error

NewTone uses Timer1, and is not a bad choice
https://bitbucket.org/teckel12/arduino-new-tone/wiki/Home
Thank you!
I've tried using NewTone and now it works.

Go Up