How to alter joystick values with Arduino Uno? I'm trying to use an Arduino Uno to read values from a 2-axis joystick analogue input, and alter these values. Rather than the true joystick values, I arithmetically convert the values at neutral to range between 0 - 5, with 'neutral', i.e. when the joystick isn't being pushed, being at roughly 2.5 for each axis. These joystick values currently output to a live text file, to be graphed in real-time. One function I'm trying to implement is that when the joystick value is greater or less than a defined value (e.g. in the code, greater than 4.55, or less than 0.5)  that the Arduino sets that point to be the new 'neutral' position (i.e. 2.5), however my code at the moment isn't working and I'm not sure how to go about attempting this.

Any insight would be most appreciated!

Cheers

const int buttonPin = 2; 
const int successPin = 13; 

int buttonState = 0;

void setup() 
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode (buttonPin, INPUT);
pinMode (successPin, OUTPUT);
while (digitalRead(buttonPin) == LOW) {};
}


void loop () {

int sensorValueY = analogRead(A0);
int sensorValueX = analogRead(A1);


//arithmetic operation that maps output values from 0 - 5 instead of 0 - 1023
float voltageX = sensorValueX * (5.0 / 1023.0);
float voltageY = sensorValueY * (5.0 / 1023.0);
Serial.print(voltageX);
Serial.print(" , ");
Serial.print(voltageY);

if (voltageX &gt;= 4.55) {
  voltageX == 2.5;
  successPin==HIGH;
  delay(1);
  successPin==LOW;
}

if (voltageX &lt;= 0.5) {
  voltageX ==2.5;
  successPin==HIGH;
  delay(1);
  successPin==LOW;
}

if (voltageY &gt;=4.55) {
  voltageY == 2.5;
  successPin==HIGH;
  delay(1);
  successPin==LOW;
}

if (voltageY &lt;= 0.5) {
  voltageY ==2.5;
  successPin==HIGH;
  delay(1);
  successPin==LOW;
}
Serial.println();

}
if (voltageX &gt;= 4.55) {
  voltageX == 2.5;
  successPin==HIGH;


The last two lines (and all similar ones later) are wrong. == is for comparing, = is for assigning. So change it to:

if (voltageX &gt;= 4.55) {
  voltageX = 2.5;
  successPin = HIGH;


You did that in a lot of places, so fix that up and get back to us.



const int successPin = 13; 
...
  successPin = HIGH;


Assuming you fix the compare to an assign you will get an error message here. You define successPin as 13, and then try to change it to 1 (which is what HIGH is defined as). Do you mean, to write to that pin? Like this?

digitalWrite (successPin, HIGH);  


You will need to change all those as well. And if you are hoping to see an LED on the pin flash, 1 ms is quite a small interval.