Skip to content

Instantly share code, notes, and snippets.

@buildcircuit
Created May 30, 2015 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buildcircuit/f1e7b398456dfdaa2066 to your computer and use it in GitHub Desktop.
Save buildcircuit/f1e7b398456dfdaa2066 to your computer and use it in GitHub Desktop.
Cosmarino- Relay control with remote control
#include <IRremote.h>
const int RECV_PIN = 7;
const int LED_PIN = 2;
const int light= 11;
IRrecv irrecv(RECV_PIN);
decode_results decodedSignal; //stores results from IR sensor
void setup()
{
pinMode(LED_PIN, OUTPUT);
pinMode(light,OUTPUT);
irrecv.enableIRIn(); // Start the receiver object
}
boolean lightState = false; //keep track of whether the LED is on
unsigned long last = millis(); //remember when we last received an IRmessage
void loop()
{
if (irrecv.decode(&decodedSignal) == true) //this is true if a message has been received
{
if (millis() - last > 250) { //has it been 1/4 sec since last message
lightState = !lightState; //toggle the LED
digitalWrite(LED_PIN, lightState);
digitalWrite(light,lightState);
}
last = millis();
irrecv.resume(); // watch out for another message
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment