Hi Everyone, I'm hoping I am missing something simple here, but I have been banging my head against the desk trying to figure this one out for a while now...
This is only a small piece of the code I have written, but essentially I have a hall effect style joystick connected to my arduino. X axis and Y axis. and I am just trying to write if statements for different positions on the joystick.
I have narrowed the problem down to this section of the code pasted below. When I am running this code, my joystick is sitting in neutral, which means LD and UD (vertical and horizontal) are both centered, and reading 50-ish. So I would expect the if statement to be false and not print "test". But it does...
The serial monitor says:
51
test
51
test
repeating.......
Any ideas?
int UDpin = A0;
int LRpin = A1;
int UDVal = 0; //variable for UD pot reading
int LRVal = 0; //variable for LR pot reading
int UD = 0; //variable for mapped UD value
int LR =0; //variable for mapped LR value
void setup() {
Serial.begin(9600);
}
void loop() {
//Read joystick pots and setup variables for each direction
UDVal = analogRead(A0);
LRVal = analogRead(A1);
UD = map(UDVal,100,920,0,100); //map values to 0-100
LR = map(LRVal,100,920,0,100); //map values to 0-100
Serial.print(UD);
if(UD>70);
{
Serial.println("test");
}
}