Este instructable mostrar cómo he creado una caja de control remoto por un transmisor infrarrojo del TV. He tomado inspiración de este instructable Control cualquier circuito con un TV remoto (y un Arduino). En este enlace pueden descubrir biblioteca le permite decodificar la señal proveniente de su remoto y las instrucciones para descargar e instalar el archivo zip de biblioteca. El objetivo de este proyecto es el reciclaje de antiguos componentes y convertir éstos en módulos electrónicos reutilizables.
CÓDIGO (véase incompleta .ino archivo adjunto)
#include...
#include...
#define MAX_TIME 150 #define LED_PIN_yellow 3 #define LED_PIN_green 4 #define LED_PIN_red 5 #define LED_PIN_blue 6 #define USB_RELAY 9 #define LAMP_RELAY 10
IRrecv irrecv(11); decode_results results; long lastPressTime = 0; int state = LOW; int blink_register = 0; int blink_fast_register = 0;
void setup() { pinMode(LED_PIN_red, OUTPUT); pinMode(LED_PIN_green, OUTPUT); pinMode(LED_PIN_yellow, OUTPUT); pinMode(LED_PIN_blue, OUTPUT); pinMode(USB_RELAY, OUTPUT); pinMode(LAMP_RELAY, OUTPUT); irrecv.enableIRIn(); // Start the receiver }
void loop() { if (irrecv.decode(&results)) { // -------------------------------------------------------- // yellow leds if (results.value == 0x443038C7) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(LED_PIN_yellow, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value // -------------------------------------------------------- // green leds if (results.value == 0x4430D827) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(LED_PIN_green, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value // -------------------------------------------------------- // red leds if (results.value == 0x443058A7) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(LED_PIN_red, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value // -------------------------------------------------------- // blue leds if (results.value == 0x443002FD) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(LED_PIN_blue, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value // -------------------------------------------------------- // USB_RELAY // BUTTON 4 if (results.value == 0x443020DF) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(USB_RELAY, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value // -------------------------------------------------------- // LAMP_RELAY // BUTTON OK if (results.value == 0x44308877) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(LAMP_RELAY, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value // -------------------------------------------------------- // all leds // button 1 if (results.value == 0x4430807F) { if (millis() - lastPressTime > MAX_TIME) { // It's been a while since the last press, so this // must be a new press. // Toggle the state state = 1 - state; (blink_register = 0); (blink_fast_register = 0); digitalWrite(LED_PIN_red, state); digitalWrite(LED_PIN_blue, state); digitalWrite(LED_PIN_yellow, state); digitalWrite(LED_PIN_green, state); } lastPressTime = millis(); } irrecv.resume(); // Receive the next value } // -------------------------------------------------------- // blink all leds // button 2 if (results.value == 0x443040BF) { (blink_register = 1); (blink_fast_register = 0); } if (blink_register == 1) { digitalWrite(LED_PIN_red, HIGH); digitalWrite(LED_PIN_yellow, HIGH); digitalWrite(LED_PIN_green, HIGH); digitalWrite(LED_PIN_blue, HIGH); delay(1000); digitalWrite(LED_PIN_red, LOW); digitalWrite(LED_PIN_yellow, LOW); digitalWrite(LED_PIN_green, LOW); digitalWrite(LED_PIN_blue, LOW); delay(1000); } // -------------------------------------------------------- // fast blink all leds // button 3 if (results.value == 0x4430C03F) { (blink_fast_register = 1); (blink_register = 0); } if (blink_fast_register == 1) { digitalWrite(LED_PIN_red, HIGH); digitalWrite(LED_PIN_yellow, HIGH); digitalWrite(LED_PIN_green, HIGH); digitalWrite(LED_PIN_blue, HIGH); delay(200); digitalWrite(LED_PIN_red, LOW); digitalWrite(LED_PIN_yellow, LOW); digitalWrite(LED_PIN_green, LOW); digitalWrite(LED_PIN_blue, LOW); delay(200); } }