ISR 쀑볡 μ‚¬μš© μ—λŸ¬

νŽŒμ›¨μ–΄ 개발 쀑에 λ‹€μŒ μ½”λ“œμ™€ 같은 μ—λŸ¬κ°€ λ°œμƒν–ˆλ‹€.

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
\arduino_build_600754\sketch\Scratch3Firmware.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1

μ•„λ‘μ΄λ…Έμ˜ 피에쑰 λΆ€μ € μ„Όμ„œλ₯Ό μ‚¬μš©ν•˜κΈ° μœ„ν•œ Tone ν—€λ”νŒŒμΌμ˜ 타이머 ν•¨μˆ˜μ™€ μΈν„°λ‘­νŠΈ μ„œλΉ„μŠ€ 루틴을 μœ„ν•΄ λ”°λ‘œ μ •μ˜ν•œ ISR(TIMER1_COMPA_vect)ν•¨μˆ˜λ₯Ό λ™μ‹œμ— μ‚¬μš©ν•  수 μ—†λŠ” λ¬Έμ œμ˜€λ‹€. μ‚¬μš©μž μ½”λ“œμ—μ„œ 이 벑터λ₯Ό μ •μ˜ν•΄ 쀑볡 μ •μ˜λ₯Ό ν•˜μ—¬ λ°œμƒν•˜λŠ” μ—λŸ¬ 메세지이닀. 두 개 λ‹€ ν”„λ‘œκ·Έλž¨ κ°œλ°œμ„ μœ„ν•΄μ„  κΌ­ ν•„μš”ν–ˆκΈ° λ•Œλ¬Έμ— ꡬ글링을 톡해 λ‹€μŒκ³Ό 같은 μ†”λ£¨μ…˜μ„ μ°Ύμ•˜λ‹€. λŒ€λΆ€λΆ„ Tone ν—€λ”νŒŒμΌκ³Ό IRRemote, NewPing λ“±μ˜ 타이머λ₯Ό μ‚¬μš©ν•˜λŠ” ν—€λ”νŒŒμΌμ„ μ€‘λ³΅ν•˜μ—¬ μ‚¬μš©ν•˜λ©΄ λ°œμƒν•˜λŠ” μ—λŸ¬μ˜€λ‹€.


SOL1) NewTone 라이브러리 이용

Tone λŒ€μ‹ μ— NewTone 라이브러리λ₯Ό μ‚¬μš©ν•΄λ΄€λ‹€. tone ν•¨μˆ˜ λŒ€μ‹  NewTone ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄ λœλ‹€. μ»΄νŒŒμΌν•˜λ‹ˆ λ‹€μŒκ³Ό 같은 μ—λŸ¬ λ©”μ‹œμ§€κ°€ 좜λ ₯됐닀.

\libraries\NewTone\NewTone.cpp.o (symbol from plugin): In function `NewTone(unsigned char, unsigned long, unsigned long)':
(.text+0x0): multiple definition of `__vector_11'
\libraries\Servo\avr\Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1

μ„œλ³΄λͺ¨ν„° λΌμ΄λΈŒλŸ¬λ¦¬μ™€ 같은 이유둜 μΆ©λŒν•œλ‹€. μ‚¬μš© λΆˆκ°€λŠ₯ν•˜λ‹€.


SOL2) TimerFreeTone 라이브러리 이용

Tone λŒ€μ‹ μ— TimerFreeTone 라이브러리λ₯Ό μ΄μš©ν•œλ‹€. toneν•¨μˆ˜ λŒ€μ‹ μ— TimerFreeTone ν•¨μˆ˜λ₯Ό μ΄μš©ν•˜λ©΄ λ˜μ§€λ§Œ noTone을 λŒ€μ²΄ν•  ν•¨μˆ˜λŠ” μ—†λ‹€. ν”„λ‘œκ·Έλž¨μ— ν•„μš”ν•œ ν•¨μˆ˜λŠ” μ•„λ‹ˆμ–΄μ„œ 없어도 λ¬΄λ°©ν–ˆλ‹€. 컴파일 ν•˜λ‹ˆ μ •μ˜ν•œ ISR ν•¨μˆ˜μ™€ μΆ©λŒλ‚˜μ§€ μ•Šκ³  μ •μƒμ μœΌλ‘œ μ»΄νŒŒμΌλ¨μ„ ν™•μΈν–ˆλ‹€. 라이브러리 이름 κ·ΈλŒ€λ‘œ 타이머λ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šμ•„μ„œ ν•΄κ²°λ˜μ—ˆλ‹€. 예제 ν”„λ‘œκ·Έλž¨μ€ λ‹€μŒ μ½”λ“œμ™€ κ°™λ‹€.

#include <TimerFreeTone.h>

#define TONE_PIN 6 // Pin you have speaker/piezo connected to (be sure to include a 100 ohm resistor).

// Melody (liberated from the toneMelody Arduino example sketch by Tom Igoe).
int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
int duration[] = { 250, 125, 125, 250, 250, 250, 250, 250 };

void setup() {}

void loop() {
  for (int thisNote = 0; thisNote < 8; thisNote++) { // Loop through the notes in the array.
    TimerFreeTone(TONE_PIN, melody[thisNote], duration[thisNote]); // Play melody[thisNote] for duration[thisNote].
    delay(50); // Short delay between notes.
  }
}


Reference