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.
}
}