1
votes

I'm trying to create a program with the IR recoder and a speaker. The objetive is to play a note when I touch a number on the remote control, but i have a problem. I was looking at the code and the problem is in the function tone, but i don´t know why.

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

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

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

collect2.exe: error: ld returned 1 exit status

exit status 1

#include "IRremote.h"

int pinLED = 7;
int pinIR = 11;
int speaker = 9;

IRrecv receptor (pinIR);
decode_results resultados;

//NOTES
long DO= 523.25;
long RE=587.33;
long MI=659.26;
long FA=698.46;
long SOL=783.99;
long LA=880;
long SI=987.77;
long DoS=554.37;


void decodificar(){

  switch(resultados.value){
    case 0xFFA25D: //POWER
      if (digitalRead(pinLED)==LOW){
        digitalWrite(pinLED, HIGH);
      }else{
        digitalWrite(pinLED, LOW);
      }
      break;

    if (digitalRead(pinLED)==HIGH){
       case 0xFF30CF: //Num 1
        tone (speaker, DO, 200);
        break;
      case 0xFF18E7: //Num 2
        tone (speaker, RE, 200);
        break;
      case 0xFF7A85: //Num 3
        tone (speaker, MI, 200);
        break;
      case 0xFF10EF: //Num 4
        tone (speaker, FA, 200);
        break;
      case 0xFF38C7: //Num 5
        tone (speaker, SOL), 200; 
        break;
      case 0xFF5AA5: //Num 6
        tone (speaker, LA, 200);
        break;
      case 0xFF42BD: //Num 7
        tone (speaker, SI, 200);
        break;
      case 0xFF4AB5: //Num 8
        tone (speaker, DoS, 200);
        break;
    }
   
  }
}

void setup() {
  pinMode (pinLED, OUTPUT);
  pinMode (speaker, OUTPUT);
  receptor.enableIRIn();
}

void loop() {

  if (receptor.decode(&resultados)){
    decodificar();
    receptor.resume();
  }
}
1
IRRemote and tone use the same timer/counter: Perhaps this one helps: stackoverflow.com/questions/53472527/…datafiddler

1 Answers

0
votes

You can use a different timer for the IRRemote library in

Arduino\libraries\IRremote\boarddefs.h

by changing the comments around line 190

#else
// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
// ATmega48, ATmega88, ATmega168, ATmega328
    #define IR_USE_TIMER1   // tx = pin 9
    //#define IR_USE_TIMER2     // tx = pin 3

For me (with a Nano) this at least removed the linker error. HTH