Pages: [1]   Go Down
Author Topic: Interrupts from IR Receiver?  (Read 549 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All
I was wondering if anyone's managed to get interrupts working properly with an IR receiver? I'm still fairly new to the arduino and haven't implemented any interrupts yet.
What I'm hoping to do is loop through a function until an IR code is received, increment a variable by 1, then run the corresponding function until a new code is received.
I've got some IR code that works, switching pins from low to high as needed, from another project.
I'm still working on the functions (animations on 2 TLC5904s) so am really fishing to see if my idea would work and hoping someone has a successful implementation I could have a nosey at smiley-grin

Thanks
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

something like this ?

http://www.ladyada.net/learn/sensors/ir.html

Duane B

rcarduino.blogspot.com
Logged


Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34726
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is that link down?
I haven't been able to access it for a couple of weeks. But you can still get it cached in Google.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
   I am able to access it directly, however it may be cached on my machine. I don't want to clear the cache to find out so lets see if the OP can have a look for us.

Duane B.

rcarduino.blogspot.com
Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I got straight through to the link. I know I don't have it cached.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The link is up for me.
That might do what I need, or at least give me some ideas thanks.
I've been using the IR library by Ken Shirrif, that works really well too but I can't get my head around getting it to interrupt and increment when I receive a signal.

Cheers for the help.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but I can't get my head around getting it to interrupt and increment when I receive a signal.
Get what to interrupt?

To interrupt what?

To increment what?

When you receive a signal from what?

I presume that the answer to the last one is "from the IR transmitter", but other ones do not seem to have answers.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul
Sorry, I lost my code moving from machines.
I've copied it below, though I'm still writing the functions.
I'm - obviously - not the best at coding but I can usually get my head around code once I figure out what it does.
This code is really basic but it makes sense to me smiley-grin I just loops to variable anim based on the code from the remote, then runs the corresponding function.
Currently it would have to wait for the function to finish before starting the loop again, probably missing the read, I was hoping I could interrupt the current function, read the code from the remote, increment or decrement anim and then run the corresponding function.

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

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
}

int anim = 1;
unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
    if (millis() - last > 250) {
      if (results.value == 0x4cb92) { // Sony DVD play
        anim + 1;
      }
      else if (results.value == 0x1cb92) { // Sony DVD stop
        anim  - 1;
      }
    }
    last = millis();
    irrecv.resume(); // Receive the next value
  }
  if (anim = 0) { // looping anim if it goes below 1
    anim = 4;
  }
  else if (anim = 5) { // looping anim if it goes above 4
    anim = 1;
  }
  else if (anim = 1) {
    // run function 1
  }
  else if (anim = 2) {
    // run function 2
  }
  else if (anim = 3) {
    // run function 3
  }
  else if (anim = 4) {
    // run function 4
  }
}

[/code]
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  if (anim = 0) { // looping anim if it goes below 1
    anim = 4;
  }
  else if (anim = 5) { // looping anim if it goes above 4
    anim = 1;
  }
  else if (anim = 1) {
    // run function 1
  }
  else if (anim = 2) {
    // run function 2
  }
  else if (anim = 3) {
    // run function 3
  }
  else if (anim = 4) {
    // run function 4
  }
I think that you are missing a few ====================. Luckily, I have some to spare. Copy and paste these into your code, as required.

An interrupt, if you create one, will not stop the long functions from running. You need to re-think how you code them, to not be blocking functions. At the very least, they need to check, periodically, to see if there has been IR input, and end if there is.
Logged

Pages: [1]   Go Up
Jump to: