Last active
April 4, 2017 13:55
-
-
Save navillus5/7550408 to your computer and use it in GitHub Desktop.
Arduino IR Remote sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Having used the sketch IRrecvDemo from the IRremote library to | |
* determine the codes for four buttons on a remote, this code will | |
* now "listen" for these codes and control LEDs based upon what code | |
* has been received. | |
*/ | |
#include <IRremote.h> | |
int RECV_PIN = 11; | |
int ledBlue = 2; | |
int ledYellow = 3; | |
int ledRed = 4; | |
// Remember to add 0x to the hexadecimal codes | |
long button1 = 0xFF728D; | |
long button2 = 0xFF52AD; | |
long button3 = 0xFF629D; | |
long button4 = 0xFFB24D; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(ledBlue, OUTPUT); | |
pinMode(ledYellow, OUTPUT); | |
pinMode(ledRed, OUTPUT); | |
irrecv.enableIRIn(); // Start the receiver | |
irrecv.blink13(true); // blink LED on P13 when IR signal is present | |
} | |
void loop() { | |
if (irrecv.decode(&results)) { | |
if (results.value == button1){digitalWrite(ledBlue, HIGH);} | |
if (results.value == button2){digitalWrite(ledYellow, HIGH);} | |
if (results.value == button3){digitalWrite(ledRed, HIGH);} | |
if (results.value == button4){ | |
digitalWrite(ledBlue, LOW); | |
digitalWrite(ledYellow, LOW); | |
digitalWrite(ledRed, LOW); | |
} | |
irrecv.resume(); // Receive the next value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment