Frozen joystick output

Hi

I connected a joystick to a arduino and sometimes, after turning the arduino on, it ramains frozen like this: https://ibb.co/nwVRZT and after resetting the board it starts working properly. Sometimes also after an hour or so it will do the same thing.

I tried a different joystick and the issue still happens. This is the code:

#include <Joystick.h>

Joystick_ Joystick;

float Multiplier = 1.2;

bool includeXAxis = true;

bool includeYAxis = true;


const int Analog1 = 0;

const int Analog2 = 1;


int XValue = 0;

int YValue = 0;


void setup() {

Joystick.begin();

delay(1000);

}


void loop() {


XValue = (analogRead(Analog1));

YValue = (analogRead(Analog2));

XValue = (XValue * Multiplier);
YValue = (YValue * Multiplier);


Joystick.setXAxis(XValue); //YAW

Joystick.setYAxis(YValue); // Throttle

}

At this point i think the board is somehow damaged?

Have you tried using any of the other analogue pins ?

Have you tried printing the value of XValue and YValue before using them with the Joystick functions and if so are they what you expect ?

I do not know what the joystick library is. Can you tell me? Better yet, provide a link to it.

How is your project wired? Can you post a pic of it? Some times, flaky connections can lead to unpredictable behavior.

Oh, a comment on code. Excess white space (blank lines) make it hard to read. And unformatted code make it hard to read and hard to identify logical block of code. Remove the excess blank lines. Hit CTRL-T to auto-format. This is what it looks like:

#include <Joystick.h>
Joystick_ Joystick;
float Multiplier = 1.2;
bool includeXAxis = true;
bool includeYAxis = true;
const int Analog1 = 0;
const int Analog2 = 1;
int XValue = 0;
int YValue = 0;

void setup() {
  Joystick.begin();
  delay(1000);
}

void loop() {
  XValue = (analogRead(Analog1));
  YValue = (analogRead(Analog2));
  XValue = (XValue * Multiplier);
  YValue = (YValue * Multiplier);

  Joystick.setXAxis(XValue); //YAW
  Joystick.setYAxis(YValue); // Throttle
}

Even better, put braces on their own line and delete blank lines in functions (also done using Auto Format by changing the options)

#include <Joystick.h>
Joystick_ Joystick;
float Multiplier = 1.2;
bool includeXAxis = true;
bool includeYAxis = true;
const int Analog1 = 0;
const int Analog2 = 1;
int XValue = 0;
int YValue = 0;

void setup()
{
  Joystick.begin();
  delay(1000);
}

void loop()
{
  XValue = (analogRead(Analog1));
  YValue = (analogRead(Analog2));
  XValue = (XValue * Multiplier);
  YValue = (YValue * Multiplier);
  Joystick.setXAxis(XValue); //YAW
  Joystick.setYAxis(YValue); // Throttle
}

UKHeliBob:
Even better, put braces on their own line and delete blank lines in functions (also done using Auto Format by changing the options)

Where might those options be set?

Where might those options be set?

Search for a file named formatter.conf on your PC and open it with an editor. All will be revealed. There are also several threads in the forum about the file and how to use it