IRremote and the mysterious led pin [Solved]

Problem in a nutshell:

Trying to get an attiny85 to read IR codes using the IRremote library. Any pin I choose to use as a LED pin goes high as soon as irrecv.enableIRIn() is called.

#include <IRremote.h>
#define F_CPU_8000000
#define __AVR_ATtiny85__
#define RECV_PIN 2
#define LED_PIN 4

unsigned long inval;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  pinMode(LED_PIN,OUTPUT);
  irrecv.enableIRIn(); // This is where things get weird
  blinkled();

 }

void loop() {
  if (irrecv.decode(&results)) {
    inval = results.value;
    irrecv.resume();
    blinkled();
  }
  delay(100);
  if (inval==0x138900FF){
    blinkled();
  }
}

void blinkled()
{
  digitalWrite(LED_PIN, HIGH);
  delay(200);
  digitalWrite(LED_PIN, LOW);
}

Other Facts :

  • Burned "bootloader" and program with 8Mhz settings
  • Uploading blink script works as it should for all led pins
  • Program runs correctly on an Nano with the same IR Receiver (TSOP 38238)
  • Other pins not specified as LED_PIN remain LOW
  • Using latest IRremote library
  • Using current attinycore

I'm stumped. Anyone have any ideas on this?

I think this has something to do with TIMER0. If you remove calls to delay() after irrecv.enableIRIn(), the thing works as it should. Does delay use TIMER0, same as IRremote?

Maybe not however.

If I remove all calls to delay() it would appear that the first call to set the LED_PIN to HIGH causes the led to turn on the immediate call to turn it off does nothing.

So, I added a second button to my circuit to send a 2nd code to the receiver to allow one button to set the led HIGH and the other to set it LOW. And that my friends works.

It could still be a timer issue in that the call to immediately turn the led off is somehow missed without a delay in between.

Alright, it probably does have something to do with timers or something like that, so here's the solution.

  1. Use the tiny_IRremote library found here :
  1. After setting any of your pins HIGH, you need to reinitialize the receiver with :

irrecv.enableIRIn();

For the blink issue, this chunk of code for blink solves the problem.

void blinkled()
{
  digitalWrite(LED, HIGH); 
  delay(200);    
  digitalWrite(LED, LOW);   
  irrecv.enableIRIn();

}