Dit instructable u tonen hoe ik heb gemaakt een doos gecontroleerd ras door een infrarood zender TV. Ik heb genomen inspiratie door dit instructable controle om het even welk Circuit met een TV Remote (en een Arduino). In deze link kunt u ontdekken bibliotheek kunt decoderen van het signaal vanuit uw afstandsbediening en de instructie aan de bibliotheek zip-bestand downloaden en installeren. Het doel van dit project is recyclen oude onderdelen en zet deze in elektronische herbruikbare modules.
CODE (onvolledige Zie Ino bestand als bijlage)
#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); } }