IrDa NEC Ported Code

/* 684 bytes without Serial & 2,566 bytes with Serial
NEC Remote (Almost every el'cheapo remote in existence)
Code adopted, converted & mangled from Original Author; 
John Davies - www.technology.com
From ATiny85 @ 1MHz for 328p @ 16MHz by JB_AU
*/

byte NextBit;
volatile unsigned long RecdData;

void ReceivedCode() {
  Serial.println(RecdData, HEX);
}

ISR(INT0_vect) {
  byte Time = TCNT0;
  byte Overflow = TIFR0 & 1<<TOV0;
  if (NextBit == 32) {
    if ((Time >= 194) && (Time <= 228) && (Overflow == 0)) {
      RecdData = 0; 
      NextBit = 0;
    } 
  } 
  else {
    if ((Time > 44) || (Overflow != 0)) NextBit = 32; // Invalid - restart
    else {
      if (Time > 26) RecdData = RecdData | ((unsigned long) 1<<NextBit);
      if (NextBit == 31) ReceivedCode();
      NextBit++;
    }
  }
  TCNT0 = 0;
  TIFR0 = TIFR0 | 1<<TOV0;
  EIFR = EIFR | 1<<INTF0;
}

void setup() {
  Serial.begin(9600); 
  TCCR0A = 0;
  TCCR0B = 5<<CS00; //Prescaler 1024, 16mhz/1024=64us
  EICRA = EICRA | 2<<ISC00;
  EIMSK = EIMSK | 1<<INT0;
  NextBit = 32;
}

void loop() {
}

I thought that was nice until someone showed me NicoHood’s IRLremote
So with some minor changes for Attiny it’s quite a decent size with a lot more desirable features & less fiddling to Transmit/Receive.

Receive_PinInterrupt.ino
Removed

#define pinIR 2

& References to Serial.

Changed

attachInterrupt(digitalPinToInterrupt(pinIR), IRLinterrupt<IR_ALL>, CHANGE);
To
attachInterrupt(0, IRLinterrupt<IR_ALL>, CHANGE);

Send_Button.ino
No change need :slight_smile:

A very nice library for any AVR :slight_smile: