mapping potentiometer values to X axis joystick values

Hey guys,

i’m trying to map the steering angle of a bike handlebar to a joystick x-axis input. i’m trying to use only one potentiometer and for now thought about keeping the y-value stable. I installed a joystick Library (https://github.com/MHeironimus/ArduinoJoystickLibrary) and the Joystick.setXAxis() requires a byte value, so between -127 and 127 while the values i get from my pot are between 0 and 1023

Used this map function to adjust the pot value range to the byte range and the values are mapped correctly when i check them with the serial monitor but when i try testing the joystick in the windows game controller, the x axis doesn’t move at all or fluctuates between some random 91 - 93 values

Here’s the code i came up with so far

#include <Joystick.h>

int xPIN = 14;
int xValue;
byte mappedX;

void setup() {
pinMode(xPIN, INPUT_PULLUP);
Joystick.begin();
}

void loop() {
  xValue = analogRead(xPIN);
  mappedX = map(xValue, 0, 1023, -127, 127);
  Joystick.setXAxis(mappedX);
  Joystick.setYAxis(0); //middle position
  delay(50);
}

sorry for my newbie approach on it :smiley: any help is greatly appreciated ^^

byte mappedX;

A byte can only be between 0 and 255

Try int mappedX;
Leo…