Go Down

Topic: Error with tone command while using the IRRemote library. (Read 399 times) previous topic - next topic

eas2pap

Hello! I am using the arduino uno board. I am working on a simple project where i control a speaker and an led with a remote control using this https://github.com/z3t0/Arduino-IRremote.git library. Everything works fine(i can get the values from the controller i use) but when i add the tone command i get an error. I am fairly new to arduino, so help is greatly appreciated. Thanks!.

Code: [Select]
#include <IRremote.h>

int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;



int speaker=7;
int RedPin=6;
int GreenPin=5;
int BluePin=3;


void setup() {
    pinMode(speaker,OUTPUT);
    pinMode(RedPin,OUTPUT);
    pinMode(GreenPin,OUTPUT);
    pinMode(BluePin,OUTPUT);
   
   
    Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
 
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, DEC);
     irrecv.resume(); // Receive the next value
    }
 
 
 
switch(results.value){
  case 3107826987:  tone(speaker,10000);
                      break;
}



}





Code: [Select]
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/716244744/build -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -libraries /tmp/716244744/pinned -libraries /tmp/716244744/custom -fqbn arduino:avr:uno -build-cache /tmp -logger humantags -verbose=false /tmp/716244744/tex

Multiple libraries were found for "IRremote.h"

Used: /home/ubuntu/opt/libraries/latest/irremote_2_2_3

Not used: /tmp/716244744/custom/Arduino-IRremote

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

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

/tmp/716244744/build/libraries/irremote_2_2_3/IRremote.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2: error: ld returned 1 exit status

exit status 1

Grumpy_Mike

The key here is :-
Quote
multiple definition of `__vector_7'
This means that both the IRremote libiary and the tone library want to use interrupt vector 7. This is the Timer2 Compare handler A.

The only way round this is to get a tome libiary that does not use Timer 2.

The problem with small systems like the processor on the Arduino is that you have a limited number of hardware resources and two different sections of code both want to use Timer 2.

Go Up