So i have this program to unlock my PC using an IR remote, and i user the "IRremote.h" and "Keyboard.h" library for arduino Leonardo, but when i press the button, my computer locks, unlocks, locks, and so on.
I found out, that the "return;" part doesn't work.
I wanted to use it to exit the loop.
Anyone knows why it doesn't work?
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include "Keyboard.h"
int x = 1;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
// Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
Keyboard.begin();
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
if (results.value == 2704)
{
if (x == 2){
delay(1000);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('l');
delay(100);
Keyboard.releaseAll();
x = 1;
return;
}
if (x == 1)
{
delay(1000);
Keyboard.press(KEY_ESC);
delay(100);
Keyboard.releaseAll();
delay(500);
Keyboard.print("8659");
x = 2;
return;
}
}
else
{
}
delay(100);
}