Skip to content

Instantly share code, notes, and snippets.

@dbarrerap
Created September 20, 2016 00:44
Show Gist options
  • Save dbarrerap/82661c5ac0bbb32563326b5c12f1ae58 to your computer and use it in GitHub Desktop.
Save dbarrerap/82661c5ac0bbb32563326b5c12f1ae58 to your computer and use it in GitHub Desktop.
#include <IRremote.h>
// Riviera Remote Control Codes
#define RivieraRED 0x2FD52AD
#define RivieraGREEN 0x2FDD22D
#define RivieraYELLOW 0x2FD32CD
#define RivieraBLUE 0x2FDB24D
#define RivieraPOWER 0x2FD48B7
// RGB LED pins
int red = 10;
int green = 9;
int blue = 8;
int rgbLED[] = {red, green, blue};
int led_state = HIGH;
// IR Receiver
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
/**
* function: encenderLED()
* parameter: char
*/
void encenderLED(char color) {
// Estado del LED es encendido
led_state = LOW;
// Apagar todos
Serial.println("Apagando...");
for(int l = 0; l < sizeof(rgbLED); l++) {
digitalWrite(rgbLED[l], HIGH);
}
Serial.println("Apagados!");
// Encender de acuerdo al color
switch (color) {
case 'r':
Serial.println("Rojo");
digitalWrite(red, LOW);
break;
case 'g':
Serial.println("Verde");
digitalWrite(green, LOW);
break;
case 'b':
Serial.println("Azul");
digitalWrite(blue, LOW);
break;
case 'y':
Serial.println("Amarillo");
digitalWrite(red, LOW);
digitalWrite(green, LOW);
break;
case 'p':
Serial.println("Purpura");
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
break;
case 'w':
Serial.println("Blanco");
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
break;
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
irrecv.enableIRIn();
for (int l = 0; l < sizeof(rgbLED); l++) {
pinMode(rgbLED[l], OUTPUT);
digitalWrite(rgbLED[l], led_state);
}
}
void loop() {
// put your main code here, to run repeatedly:
if(irrecv.decode(&results)) {
// Prender de acuerdo al resultado
switch (results.value) {
case RivieraRED:
encenderLED('r');
break;
case RivieraGREEN:
encenderLED('g');
break;
case RivieraBLUE:
encenderLED('b');
break;
case RivieraYELLOW:
encenderLED('y');
break;
case RivieraPOWER:
led_state = !led_state;
for (int l = 0; l < sizeof(rgbLED); l++) {
digitalWrite(rgbLED[l], led_state);
}
break;
default:
Serial.println("Codigo no reconocido");
}
irrecv.resume();
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment