Skip to content

Instantly share code, notes, and snippets.

@navin-mohan
Created April 30, 2016 10:59
Show Gist options
  • Save navin-mohan/f54a37f9184f747be42a7218875772fe to your computer and use it in GitHub Desktop.
Save navin-mohan/f54a37f9184f747be42a7218875772fe to your computer and use it in GitHub Desktop.
TV remote
#include <IRremote.h> //include the IR library
//#define DEBUG 0 //enable debug mode
#define LED_PIN 13 //the pin showing the output
int IR_pin = 4; //digital pin connected to output of the TSOP
unsigned long currentCode=0,storedCode=0; //to store the recieved code for comparison
bool outputState = 0; //stores the default output state of the lED that is OFF
IRrecv irrecv(IR_pin); //create an IRrecv object
decode_results results; //object to store the decoded IR signal
void setup(){ //initial set up only runs once when the device is reset
#ifdef DEBUG
Serial.begin(9600); //start serial communication with the computer
#endif
irrecv.enableIRIn(); //start the reciever
pinMode(LED_PIN,OUTPUT); //set the led pin as output
digitalWrite(LED_PIN,outputState); //set the default output state
}
void loop(){
if(irrecv.decode(&results)){ //decode the incoming data if any
currentCode = results.value; //store the recieved value
#ifdef DEBUG
Serial.println(currentCode);
Serial.println(storedCode);
#endif
if(currentCode == storedCode){ //if the user sends the same code again
outputState =!outputState; //toggles output
#ifdef DEBUG
Serial.println(outputState);
#endif
}
storedCode = currentCode; //stores the previous value
irrecv.resume(); //recieve the next value
}
digitalWrite(LED_PIN,outputState); //set the output state
delay(100); //wait for 100ms
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment