/* IR Remote Control Switch David Johnson-Davies - www.technoblogy.com - 6th June 2015 ATtiny85 @ 1 MHz (internal oscillator; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ // Outputs int Output[] = {4, 3, 0, 1, 1}; volatile int NextBit; volatile unsigned long RecdData; // Adafruit Remote Control // Buttons: 1 2 3 4 // Codes: 0x10 0x11 0x12 0x14 (yes there is a gap!) void ReceivedCode(boolean Repeat) { // Check for correct remote control if ((RecdData & 0xFFFF) != 0xbf00) return; // Read key pressed int key = RecdData>>16 & 0xFF; // Keys 1, 2, 3, and 4 toggle the corresponding switch on/off if ((key >= 0x10) && (key <= 0x14) && !Repeat) { int pin = Output[key - 0x10]; digitalWrite(pin, !digitalRead(pin)); } } // Interrupt service routine - called on every falling edge of PB2 ISR(INT0_vect) { int Time = TCNT0; int Overflow = TIFR & 1<= 194) && (Time <= 228) && (Overflow == 0)) { RecdData = 0; NextBit = 0; } else if ((Time >= 159) && (Time <= 193) && (Overflow == 0)) ReceivedCode(1); // Data bit } else { if ((Time > 44) || (Overflow != 0)) NextBit = 32; // Invalid - restart else { if (Time > 26) RecdData = RecdData | ((unsigned long) 1<