Hi all,
So I'm trying to make some code that'll measure and read out the values of a joystick in a neutral position for a calibration. My main issue is that I'd really like these measurements to be global variables. However, with the code below, Serial.println(xMeasure) and Serial.println(yMeasure) return 0. When I move int xMeasure = calibrate(xPin); and int yMeasure = calibrate(yPin); inside the loop, everything works perfectly, but then they run every time loop runs.
I'm using a Parallax 2-axis joystick with range 0-1000 for both potentiometer axes.
Thanks for any help,
Chris
const int yPin = A0;
const int xPin = A1;
int xMeasure = calibrate(xPin);
int yMeasure = calibrate(yPin);
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(xMeasure);
Serial.println(yMeasure);
}
int calibrate(int pin) {
const int testNum = 25;
int measure = 0;
int i = 0;
pinMode(pin,INPUT);
do{
measure += analogRead(pin);
i++;
}while (i < testNum);
measure = measure/testNum;
return measure;
}