Keyboard library functions stop working. Leonardo

Hello, I try to emulate WASD keys with a joystick and an Arduino Leonardo Board. I managed to find a little tutorial and make it work, however it had high latency.
So I have searched for other solutions and uploaded several codes to the board (like trying the joystick ) but none succeeded.
So I went back to the first code I found, uploaded it and no keyboard function doesn't work anymore. Here is the code , it's a little different from the one I found because I wanted to check what's wrong:

#include<Keyboard.h>

const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = A0; // analog pin connected to X output
const int Y_pin = A1; // analog pin connected to Y output
int x, y;
void setup() 
{
  pinMode(SW_pin, INPUT); // SW pin set as input
  digitalWrite(SW_pin, HIGH); // A high value is written to SW pin
  Serial.begin(115200);
  Keyboard.begin();
}
void loop() 
{
  x = analogRead(X_pin); // output of X_pin is read
  if (x  > 1000) // check whether the value of x = 1023
  {
    Keyboard.press(KEY_LEFT_ARROW); 
    Keyboard.print("www.deagware.xyz");
    Keyboard.write(65);
    Serial.println("Left:");
    // key moves left 215
  }
  else
  {
    Keyboard.release(KEY_LEFT_ARROW);  // release the key
  }
  x = analogRead(X_pin);  // output of X_pin is read
  if (x == 0) // check whether the value of x = 0

  {
    Serial.println("Right:");
    Keyboard.press(KEY_RIGHT_ARROW); // key moves right 216
  }
  else
  {
    Keyboard.release(216);  // release the key
  }
  y = analogRead(Y_pin);  // output of Y_pin is read
    if (y == 1023) // check whether the value of  y = 1023
    {
      Serial.println("Down:"); 
      Keyboard.press(KEY_DOWN_ARROW); // key moves down 217
    }
    else
    {
     Keyboard.release(217);  // release the key
    }
  y = analogRead(Y_pin); // output of Y_pin is read

    if (y == 0) // check whether the value of y = 0
    {
      Serial.println("Up:");
      Keyboard.press(KEY_UP_ARROW); // key moves up 218

  }
  else
  {
    Keyboard.release(218);  // release the key
  }
  int z = digitalRead(SW_pin); // read the value of SW pin
    if (z == 0) //check whether the value of z = 0
    {
      Serial.println("Enter:");
      Keyboard.println(); //enter key is pressed
   }
  //delay(500);
}
  • So now I get serial print in serial monitor and that's all.

  • The arduino is recognised as keyboard in perheral devices.

  • I am not 100% sure but I think that on the Arduino Board, when the keyboard function worked at the begining, the L led (between TX and ON leds) was on . Now it doesn't turn on anymore when I upload my code

*I have already reset the arduino many times since Keyboard functions stopped working

Up

I also remember that I launched Overwatch and in game was the first time I noticed my arduino program doesn't respond. I know that movement bug (such as no keyboard response) was reported by Overwatch players

I also installed various libraries related to joystick and keyboard in Arduino IDE, maybe there are conflicts.

By the way, how do I check #include keyboard.h has been correctly compiled? No message error when compiling but not a single keyboard function doesn't work

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.