joystick problem slowly increasing of adding higher numbers

I use a ps3 joystick to control a variable . When I use the joystick to the maximum i noticed that when the variable is low the progress of increasing the variable is much slower than when the variable is higher.

#include <PS3USB.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
//PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printAngle;
uint8_t state = 0;

// Arduino code for Neopixel LED controller
// using a joystick
// (C) Ismail Uddin, 2015

#include <Adafruit_NeoPixel.h>
#define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);

// set pin numbers for joystick axes:
const int xAxis = LeftHatY; // Right joystick Y axis
const int yAxis = LeftHatY; // Left joystick Y axis

// parameters for reading the joystick:
int range = 50; // output range of X or Y movement
int responseDelay = 0; // response delay of the mouse, in ms
int threshold = range / 4; // resting threshold
int center = range / 2; // resting position value

int reading = 0;
int readingtemp = 0;
int readingbyte = 0;
int prevreadingbyte = 0;
int lengtepot = 20;
int val = 0;

int x;

int prevVal = 0;

int ps3check = 0;

void setup()
// put your setup code here, to run once:
delay(2000);//give ps3 controller time for startup
// open a serial connection to display values
Serial.begin(115200); // 9600);
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start/r/n"));
while (1); //halt
Serial.print(F("\r\nPS3 USB Library Started"));


void loop() {


if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

int xReading = readAxis(LeftHatY);

readingbyte = reading/8;

val = map(reading, 0, 1023, 0, lengtepot);

if (readingbyte != prevreadingbyte)
Serial.print("FF 01 ");
prevreadingbyte = readingbyte;

int readAxis(int thisAxis) {
int reading = PS3.getAnalogHat(thisAxis);//read the ps3 input:
reading = map(reading, 0, 255, range, 0); // map the reading from the ps3 input range to the output range:
int distance = reading - center;// if the output reading is outside from the rest position threshold, use it:
if (abs(distance) < threshold) {
distance = 0;
// return the distance for this axis:
return distance;

The code posted does not compile. Function defined inside loop function, curly braces messed up. So it cannot exhibit the behavior you describe.

Please read the "How to use this forum - please read" thread at the top of any of the message boards and learn to post code correctly.

Please post complete code that can compile unless your issue is a compiler message, in which case post EXACTLY the code that caused the message and EXACTLY the message you see.