I'm trying to control my PC volume using a IR remote control. Right now it works, but for each step UP or DOWN I have to press the button again and again and again. I'd love to make it work just as the TV works, so when you hold the V+ button the volume rises up for how long you keep the button hold and same with V-.
#include <IRremote.h>
#include <HID-Project.h>
#include <HID-Settings.h>
#define code1 16732335 // Volume Down
#define code2 16742535 // Volume Up
#define code3 4294967295 // Hold
int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
irrecv.enableIRIn();
}
void loop() {
unsigned int last=0;
if (irrecv.decode(&results))
{
unsigned int i = results.value;
if(i==code3)
i=last;
else // i==code1 || i==code2
last=i;
switch(i)
{
case code1: // Volume Down
Keyboard.press(KEY_RIGHT_CTRL);
Keyboard.press(KEY_F11);
delay(50);
Keyboard.releaseAll();
break;
case code2: // Volume Up
Keyboard.press(KEY_RIGHT_CTRL);
Keyboard.press(KEY_F12);
delay(50);
Keyboard.releaseAll();
break;
}
irrecv.resume();
}
}
What is wrong in the code?