I'm working on a project that i want to controll with an IR remote. to make have the comunication smooth I connected the IR receiver to D2 on my arduino nano so i could use the interrupt function. But when i try to read the remote(wich is an other arduino) it gives a bunch of strange values. It should be 0xA90. when i try to read the value without using the interrupt it works fine.
How do you suppose that the IR library works? What mechanism do you think it uses to receive data?
If you said anything but "Interrupts, of course", you got it wrong. If you did say "Interrupts, of course", then please explain how you think interrupts will be triggered while your ISR is working.
Here is a library example of receiving IR commands without using an interrupt:
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
This will loop until the following condition is true:
(irrecv.decode(&results))
Then print the results which have been collected.
If you want to process by an ISR, you would have to create a similar loop in that ISR, waiting until the results were there.
The problem is, as has already been pointed out, this would interfere will the collection of the very results you are waiting for.
The IR library uses a timer driven ISR with a period of 50 microseconds to process the sensor results, and this would be blocked while servicing your own ISR.
What are you trying to achieve by using an ISR here ?
But how do i read the IR input when i'm in an other loop.
For example I'm in a loop that plays an animation on a led matrix and i want to use receive the ir signal. how do i do that?