Hi, using a Leonardo to control basic media stuff (volume, pause, etc) on my pc with an old ir remote. The receiver diode is plugged in to gnd, 5v, and pin 7, and i'm using IRLib2 and HID-Project in my code. I am not using a separate power supply for the board, just the usb cable.
My method of recognizing ir codes is a little janky due to the age of the remote, but when I'm testing it, looking at the serial monitor it works fine, and for example i can hold down a button and go from 0 volume to 100 in about 5 seconds, and an led on the board stays solid as long as I'm holding the button.
When I'm doing this though, if I close the IDE, the code seems to slow down greatly, only recognizing a button press about once a second. The led on the board also only flashes now once a second. If I reopen the IDE it goes back to functioning normally, I don't even have to reupload the sketch or anything.
This is probably something simple about how serial works or something but I can't find anything on it, so thought I'd ask here. I've already tried a few differed baud rates and completely removing delays. Here's the code:
#include <IRLibRecvPCI.h>
#include <HID-Project.h>
IRrecvPCI myReceiver(7);//pin number for the receiver
void setup() {
Consumer.begin();
Serial.begin(9600);
delay(2000); while (!Serial); //delay for Leonardo
myReceiver.enableIRIn(); // Start the receiver
Serial.println(F("Ready to receive IR signals"));
}
int g=0;
void loop() {
//Continue looping until you get a complete signal received
if (myReceiver.getResults()) {
for(bufIndex_t i=1;i<recvGlobal.recvLength;i++) {
Serial.print(recvGlobal.recvBuffer[i]);
}
if(recvGlobal.recvLength>6){
Serial.print(F("TOO BIG "));
}
else if(recvGlobal.recvLength>3){
if(recvGlobal.recvBuffer[2]>=4000 && recvGlobal.recvBuffer[2]<=4070){
Serial.print(F("VOL UP"));
Consumer.write(MEDIA_VOLUME_UP);
}
else if(recvGlobal.recvBuffer[2]>=1500 && recvGlobal.recvBuffer[2]<=1555){
Serial.print(F("VOL DOWN"));
Consumer.write(MEDIA_VOLUME_DOWN);
}
else if(recvGlobal.recvBuffer[2]>=7050 && recvGlobal.recvBuffer[2]<=7100){
Serial.print(F("NEXT"));
Consumer.write(MEDIA_NEXT);
}
}
else{
if(recvGlobal.recvBuffer[0]>=9000 && recvGlobal.recvBuffer[0]<=9050){
Serial.print(F("PREV"));
Consumer.write(MEDIA_PREVIOUS);
delay(8);
}
if(recvGlobal.recvBuffer[2]>=7800 && recvGlobal.recvBuffer[2]<=7850){
if (g==0){
Serial.print(F("MUTE"));
Consumer.write(MEDIA_VOLUME_MUTE);
g=2;
}
if (g>0){
Serial.print(F("input paused"));
}
}
}
Serial.print(F(", "));
delay(40);
if (g>0){
Serial.print(F("down"));
g--;
}
myReceiver.enableIRIn(); //Restart receiver
}
}