Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This sample code is for Controlling LED on Maker UNO (Arduino) using IR Remote's Tutorial.
// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>
// Define sensor pin
const int RECV_PIN = 4;
// Define LED pin
#define RED 8
#define GREEN 9
#define YELLOW 10
#define BLUE 11
// Define integer to remember toggle state
int redState = 0;
int greenState = 0;
int yellowState = 0;
int blueState = 0;
// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
// Enable the IR Receiver
irrecv.enableIRIn();
// Set LED pins as Outputs
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(BLUE, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
switch (results.value) {
case 0xCD3221DE:
if (redState == 0) {
digitalWrite(RED, HIGH);
redState = 1;
}
else {
digitalWrite(RED, LOW);
redState = 0;
}
break;
case 0xCD32916E:
if (greenState == 0) {
digitalWrite(GREEN, HIGH);
greenState = 1;
}
else {
digitalWrite(GREEN, LOW);
greenState = 0;
}
break;
case 0xCD329B64:
if (yellowState == 0) {
digitalWrite(YELLOW, HIGH);
yellowState = 1;
}
else {
digitalWrite(YELLOW, LOW);
yellowState = 0;
}
break;
case 0xCD326996:
if (blueState == 0) {
digitalWrite(BLUE, HIGH);
blueState = 1;
}
else {
digitalWrite(BLUE, LOW);
blueState = 0;
}
break;
}
irrecv.resume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment