Hola buenas,
Me gustaría controlar un motor con un mando infrarrojo, quisiera que se encendiera solo cuando dejo pulsado una tecla y cuando dejo de pulsarla que se desconecte. Dejo el codigo que he podido hacer hasta este momento, este codigo el problema que tiene es que durante un pequeño tiempo se apaga y luego vuelve a reconocer que estoy pulsado el mando. Muchas gracias.
#include "IRLremote.h"
const int interruptIR = 0; // Arduino interrupcion 0: Pin 2
int rele = 13;
uint8_t IRProtocol = 0; // Variables para recibir los datos
uint16_t IRAddress = 0;
uint32_t IRCommand = 0;
void setup()
{ Serial.begin(115200); // Fijate en la velocidad
pinMode(rele, OUTPUT);
Serial.println("Startup");
IRLbegin<IR_ALL>(interruptIR);
}
void loop()
{
uint8_t oldSREG = SREG; // Parar las interrupciones
cli();
if (IRProtocol) // Si reconoce el protocolo
{
Serial.print("Protocol:");
Serial.println(IRProtocol);
Serial.print("Address:");
Serial.println(IRAddress, HEX);
Serial.print("Command:");
Serial.println(IRCommand, HEX);
IRProtocol = 0;
}
SREG = oldSREG;
while (true){
while (IRCommand == 0xFFFF){
digitalWrite(rele, HIGH);
delay (600);
IRCommand = 0x45e3;
}
digitalWrite(rele, LOW);
}
}
void IREvent(uint8_t protocol, uint16_t address, uint32_t command)
{
IRProtocol = protocol; // Recogemos los valores y nos volvemos
IRAddress = address;
IRCommand = command;
}