So I'm trying to use a joystick to turn on an led. I have succeeded in doing so but with only one of the values received by the joystick. If I wanted to use more of the values by the joystick, I would have to use a lot of if else statements. So to simplify it, I was wondering how to use an array to combine all the values into one int. But when I go to compile, I get the error:
C:\Users\tyler\AppData\Local\Temp\arduino_modified_sketch_379286\sketch_feb26a.ino: In function 'void led()':
sketch_feb26a:43: error: lvalue required as left operand of assignment
if(value1 = valueR1 && value2 = valueR2)
^
exit status 1
lvalue required as left operand of assignment
How would I combine the values and use them?
int led1 = 13; //top
int led2 = 12; //bottom
int led3 = 11; //right
int led4 = 10; //left
int joy1 = 0; //joystick pin
int joy2 = 1; //joystick pin
int value1 = 0; //first value from joystick
int value2 = 0; //second value from joystick
int valueR1[] = {49,50,51,52,53,54}; //value1 #'s received that i want to use to turn on right led
int valueR2[] = {53,54,55,56}; //value2 #'s received that i want to use to turn on left led
void setup()
{
pinMode(led1, OUTPUT); //top led
pinMode(led2, OUTPUT); //bottom led
pinMode(led3, OUTPUT); //right led
pinMode(led4, OUTPUT); //left led
Serial.begin(9600);
}
//simplify numbers received by 2 axis-joystick
int treatValue(int data)
{
return (data * 9 / 1024) + 48;
}
void loop()
{
value1 = analogRead(joy1);
delay(50);
value2 = analogRead(joy2);
Serial.print(treatValue(value1));
Serial.println(treatValue(value2));
led();
}
void led()
{
value1 = (value1 * 9 / 1024) + 48;
value2 = (value2 * 9 / 1024) + 48;
//turn on led on right
if(value1 = valueR1 && value2 = valueR2)
{
digitalWrite(led3, HIGH);
}
else
{
digitalWrite(led3, LOW);
}
}
This is the table I created to show the values received by joystick