Welcome! Share code as fast as possible.

#include "HID-Project.h"

#define INPUT_PIN A10

uint16_t rawADC = 0;
uint16_t SliderValue = 0;

const int numberOfPotSamples = 10;      // Number of pot samples to take (to smooth the values)
const int delayBetweenSamples = 2;      // Delay in milliseconds between pot samples
const int delayBetweenHIDReports = 10;  // Additional delay in milliseconds between HID reports

void setup() {
  analogReadResolution(12);
  Gamepad.begin();
}

void loop() {
  int potValues[numberOfPotSamples];  // Array to store pot readings
  int potValue = 0;                   // Variable to store calculated pot reading average

  // Populate readings
  for (int i = 0; i < numberOfPotSamples; i++) {
    potValues[i] = analogRead(INPUT_PIN);
    potValue += potValues[i];
    delay(delayBetweenSamples);
  }

  // Calculate the average
  potValue = potValue / numberOfPotSamples;

  // Map analog reading from 30 ~ 4095 to 127 ~ -128 for use as an axis reading
  int adjustedValue = map(potValue, 30, 4095, 127, -128);
  Gamepad.zAxis(adjustedValue);
  Gamepad.write();
  delay(delayBetweenHIDReports);
}