Trying to use a hall effect magnet sensor

Hi there.

I am trying to make a handbrake work on PS4. I have tested my arduino pro micro and the hall pass sensor (magnetic) with the below code which works on PC fine but i now need to change it to a keyboard press so the playstation will think when pulling the hand brake its pushing a key on the keyboard any help would be appreciated please.

#include <Joystick.h>

Joystick_ Joystick;
int zAxis_ = 0; 

void setup() {
  Joystick.begin();

}

void loop() {
  zAxis_ = analogRead(A2);
  Joystick.setZAxis(zAxis_);
  Serial.println(zAxis_);
  delay(20);

}

This one dosnt work it constantly puts Q's up and wont stop

#include <Keyboard.h>
void setup()

{pinMode(A2, INPUT); }
   

const int pinToButtonMap = A2;

void loop()

{int pot = analogRead(A2);
int mapped = map(pot,0,1023,0,255);

while (analogRead(A2) == HIGH) {}
  Keyboard.press("Q");
  Keyboard.releaseAll();
  delay(200);
  while (analogRead(A2) == LOW) {}

}

Remove all excess crap from your code and make it look like the first (working) version. Then compare the analog values with meaningful analog values, not digital values HIGH and LOW.

thanks thats great

i need to change the joystick component to keyboard component but analog are you able to help ?

i have ground, vcc wired up and data wire for A2 on board just fyi

How will you detect a new analog value that should be transmitted?

#include <Keyboard.h>

void setup() {}

void loop()
{
  if (analogRead(A2) > 1000)
  {
    Keyboard.write('Q');
    delay(200);
    while (analogRead(A2) > 600) {/* Do Nothing */}
  }
}