Hello!
So I have this random issue with my DIY "Flirc" built one pro micro clone. It consits of IR Reciver and a an external diode so nothing complicated. When connect to the PC it can work fine for few hours to suddenly stop receiving IR messages from the remote. I have to walk up the receiver and press a button on my remote for a few times to get a reaction.
What tried to do is:
- unplug and plug the usb - no change
- restarting pc - no change
- trying different USB port (all 2.0 but i had it plugged to a 3.0 for a while in the beginning it would have the same problem sometimes)
- different remote sending the same ir singlas - no change
- moving the receiver to a different spot (0.5m every direction)
- connecting to a different pc - works fine on pc no.2, but plugged back to pc no.1 and issue still persists.
What works is simply wait (few minutes) and it starts working properly again.
Of course during the "fritz time" pc works fine, other usb devices work properly.
ANY suggestion would be much appreciated
and of course the code:
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
#include <Keyboard.h>
int RECV_PIN = 10;
unsigned long recv_tmp;
bool tv = 1;
int ctrlLed = 9;
int repeat = 0;
bool repeatCont = false;
//unsigned long time;
//int timeDif;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
pinMode(ctrlLed, OUTPUT);
Keyboard.begin();
}
void button() {
}
void loop() {
if (tv)
{
digitalWrite(ctrlLed, LOW);
// Serial.println("TV Mode");
} else
{
digitalWrite(ctrlLed, HIGH);
// Serial.println("PC Mode");
}
if (irrecv.decode(&results)) {
if (results.value != 0xFFFFFFFF){
recv_tmp = results.value;
repeat = 0; //repetition countr (acts as debouncer also)
repeatCont = false; //continues press of a button
}
else {
repeat++;
if (repeat > 4) {
repeatCont = true;
}
}
//Serial.println(results.value, HEX);
if (repeat == 0 or repeatCont){
if (recv_tmp == 0x20DF4EB1){
if (tv) {
tv=false;
} else {
tv=true;
}
}
else if (tv == false)
{
switch (recv_tmp)
{
case 0x20DF10EF: //power
case 0x20DFD02F: //input
case 0x20DF807F: //channel-
case 0x20DF00FF: //channel+
Serial.println("TV");
digitalWrite(ctrlLed, LOW);
tv = true;
break;
case 0x20DF02FD:
Serial.println("gora");
Keyboard.write(218);
break;
case 0x20DF827D:
Serial.println("dol");
Keyboard.write(217);
break;
case 0x20DFE01F:
Serial.println("lewo");
Keyboard.write(216);
break;
case 0x20DF609F:
Serial.println("prawo");
Keyboard.write(215);
break;
case 0x20DF22DD:
Serial.println("ok");
Keyboard.write(176);
break;
case 0x20DF14EB:
Serial.println("back");
Keyboard.write(178);
break;
case 0x20DF40BF:
Serial.println("+");
Keyboard.write(43);
break;
case 0x20DFC03F:
Serial.println("-");
Keyboard.write(45);
break;
case 0x20DF0DF2:
Serial.println("play");
Keyboard.write(112);
break;
case 0x20DF8D72:
Serial.println("stop");
Keyboard.write(120);
break;
case 0x20DFDA25:
Serial.println("exit");
Keyboard.press(KEY_ESC);
delay(20);
Keyboard.releaseAll();
break;
case 0x20DF8679:
Serial.println("blue");
Keyboard.write(99);
break;
case 0x20DF9C63:
Serial.println("subtitle");
Keyboard.write(108);
break;
case 0x20DF8976:
Serial.println("AD");
Keyboard.write(119);
break;
case 0x20DF906F:
Serial.println("MUTE");
Keyboard.press(KEY_F8);
delay(20);
Keyboard.releaseAll();
break;
/*
case 0x20DF8976:
Serial.println("AD");
Keyboard.write(119);
break;
case 0x20DF8976:
Serial.println("AD");
Keyboard.write(119);
break;
*/
default:
Serial.println(results.value, HEX);
break;
}
}
}
irrecv.resume(); // Receive the next value
}
delay(150);
}