hi, i am trying to get this code where the color of an led changes depending on the x and y values of a joystick (HW-504). they both work separately but i cannot get the code to work and keep getting
"exit status 1
'else' without a previous 'if'" for all my 'else' commands.
i have the VRX of the joystick connected to A0 and the VRY connected to A1.
the RGB led is connected to 5(red) , 6(green), 7 (blue)
here is my code, if you can find a problem it would be greatly appreciated:
#define VRX_PIN A0 // Arduino pin connected to VRX pin
#define VRY_PIN A1 // Arduino pin connected to VRY pin
int xValue = 0; // To store value of the X axis
int yValue = 0; // To store value of the Y axis
int r=5;
int g=6;
int b=7;
void setup() {
Serial.begin(9600) ;
pinMode(r,OUTPUT);
pinMode(g,OUTPUT);
pinMode(b,OUTPUT);
}
void loop() {
// read analog X and Y analog values
xValue = analogRead(VRX_PIN);
yValue = analogRead(VRY_PIN);
if (digitalRead(xValue)> 1015)
(digitalRead(yValue)> 517);
(digitalRead(yValue)< 520);{
Serial.println("blue");
digitalWrite(b,HIGH);
delay(100);
}
else
{digitalWrite(b,LOW);}
if (digitalRead(xValue)< 5)
(digitalRead(yValue)> 517);
(digitalRead(yValue)== 520);
(digitalRead(yValue)== 519);
(digitalRead(yValue)== 518);{
Serial.println("green");
digitalWrite(g,HIGH);
delay(100);
}
else
{digitalWrite(g,LOW);}
if (digitalRead(yValue)> 1010)
(digitalRead(xValue)== 513);{
Serial.println("red");
digitalWrite(r,HIGH);
delay(100);
}
else
{digitalWrite(r,LOW);}
if (digitalRead(yValue)< 5)
(digitalRead(xValue)== 513);{
Serial.println("porpol");
digitalWrite(b,HIGH);
digitalWrite(r,HIGH);
delay(100);
}
else
{digitalWrite(b,LOW);
digitalWrite(r,LOW);}
// print data to Serial Monitor on Arduino IDE
Serial.println("x = ");
Serial.print(xValue);
Serial.println(", y = ");
Serial.print(yValue);
Serial.println(" ");
}