Hi, I'm pretty new to arduino. I'm trying to make a 8x8 led matrix to work with a joystick but i,m getting a weird output from a IF statment. I want the code to do nothing except X or Y are <300 or >700. The IF validates even the x or y are 500.
void loop()
{
int xValue = analogRead(joyX);
int yValue = analogRead(joyY);
if (analogRead(xValue)>700 && posCol<7){lc.setLed(0,posCol,posLin,false);posCol = posCol + 1;Serial.print( "x"); Serial.print( xValue);goto bailout;}
if (analogRead(yValue)>700 && posLin<7){lc.setLed(0,posCol,posLin,false);posLin = posLin + 1;Serial.print( "y"); Serial.println( yValue);goto bailout;}
if (analogRead(yValue)<300 && posLin>0){lc.setLed(0,posCol,posLin,false);posLin = posLin - 1;Serial.print( "y"); Serial.println( yValue);goto bailout;}
if (analogRead(xValue)<300 && posCol>0 ){lc.setLed(0,posCol,posLin,false);posCol = posCol - 1;Serial.print( "x"); Serial.print( xValue);goto bailout;}
//else if (digitalRead(SW_pin)==0){delay(200);lc.setLed(0,posCol,posLin,true);posCol = posCol - 1;}
bailout:
delay(50);
lc.setLed(0,posCol,posLin,true);
}
Serial Output
x1014x1014x1014x1014x790y512
y512
y512
y512
y515
y515
y515
y515
y515
x0x0x0x0x0y1023
x509x509x509y735
y769
x509x509x509y1023
y799
x508y1020
Please help me out here
Thanks