Skip to content

Instantly share code, notes, and snippets.

@buildcircuit
Created May 24, 2015 06:29
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/0ecf3678349e430cad4a to your computer and use it in GitHub Desktop.
Save buildcircuit/0ecf3678349e430cad4a to your computer and use it in GitHub Desktop.
Lamp on and off with remote and phone
#include <IRremote.h>
int redLed = 9;
const int irReceiverPin = 2;
const int ledPin = 3;
IRrecv irrecv(irReceiverPin); //create an IRrecv object
decode_results decodedSignal; //stores results from IR sensor
void setup() {
Serial.begin(9600);
pinMode(redLed,OUTPUT);
analogWrite(redLed,20);
pinMode(ledPin, 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(ledPin, lightState);
analogWrite(redLed,0);
}
last = millis();
irrecv.resume(); // watch out for another message
}
if (Serial.available() > 0) {
int thisChar = Serial.read();
// say what was sent:
Serial.print("You sent me: \'");
Serial.write(thisChar);
if (thisChar=='h')
{
digitalWrite(9, HIGH);
}
else {
digitalWrite(9, LOW);
}
Serial.print("\' ASCII Value: ");
Serial.println(thisChar);
Serial.println();
Serial.println("Give me another byte:");
Serial.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment