Im using 9 LED in a shape of a cross, 1 in the middle 2 on each edge. I want to control the lights of the LED with a joystick. For example, if the joystick is tilted all the way to the left, the LED on the far left edge will light up. If the joy stick is tilted slightly to the left, the LED between the far left LED and the middle LED will light up. Here is my sketch could you all please help me?
int joystick_x = A0;
int joystick_y= A1;
void setup()
{
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
Serial.begin(9600);
}
void loop() {
int val_0 = analogRead(A0);
int val_1 = analogRead(A1);
Serial.print("VRx : ");
Serial.print(val_0);
Serial.print(" ");
Serial.print("VRy : ");
Serial.println(val_1);
delay(1000);
if (val_0 <250 && 509 >val_1>505) {
digitalWrite(6,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
else if (val_0>250 && val_0 < 505 && 509 >val_1> 505) {
digitalWrite(5,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
else if (515 > val_0> 514 && val_1< 250){
digitalWrite(3,HIGH);
digitalWrite(6,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
}
else if (515 >val_0> 514 && val_1>250 && val_1 <505) {
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
else if (val_0 <800 && val_0> 515 && 507 >val_1> 505){
digitalWrite(9,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(6,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
else if (val_0 > 800 && 507 > val_1> 505) {
digitalWrite(10,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(6,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
}
else if (515 > val_0> 514 && val_1 >508 && val_1 < 800){
digitalWrite(7,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
else if (515 > val_0> 514 && val_1 >800) {
digitalWrite(8,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
else if (515 > val_0 > 514 && 507 > val_1> 505) {
digitalWrite(11,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(6,LOW);
}
}