LED won't turn off fully when surrounded by other "on" LEDS

Messing around with arduino, and I made a line of LEDs where I can "Control" a single HIGH led with a joystick. I can "move" this HIGH led left and right on the line: GIF | Gfycat

int led[] = {2,3,4,5,6,7,8,9,10,11,12,13};

void setup() {
  Serial.begin(9600);

for (int i = 0; i < 12; i++){
   pinMode(led[i], OUTPUT);
   digitalWrite(led[i], LOW);
  }
}

void loop() {
  int xAxis = analogRead(A0);
  int yAxis = analogRead(A1);
  int count = led[0];
  
  Serial.println(xAxis);
  
  xAxis = map(xAxis, 0, 1020, 0, 11);
  for (count ; count < 14; count++){
   digitalWrite(led[xAxis], HIGH);
   delay(1);
   digitalWrite(led[xAxis], LOW);
}

This all works as intended. But when I tried to get the opposite effect, all I did was switch the digitalWrites HIGH and LOW expecting to get control of a single LOW led and the rest would stay HIGH. that being said, the LOW led doesn't fully turn off: GIF | Gfycat

int led[] = {2,3,4,5,6,7,8,9,10,11,12,13};

void setup() {
  Serial.begin(9600);

for (int i = 0; i < 12; i++){
   pinMode(led[i], OUTPUT);
   digitalWrite(led[i], LOW);
  }
}

void loop() {
  int xAxis = analogRead(A0);
  int yAxis = analogRead(A1);
  int count = led[0];
  
  Serial.println(xAxis);
  
  xAxis = map(xAxis, 0, 1020, 0, 11);
  for (count ; count < 14; count++){
   digitalWrite(led[xAxis], LOW);
   delay(1);
   digitalWrite(led[xAxis], HIGH);
}

Any help would be greatly appreciated.

Why i<12 and count<14 ?

Put this as the first line at the top of your program, outside of setup()

#define ELEMENTS(x)  (sizeof(x) / sizeof(x[0]))

This is a preprocessor macro that determines the number of elements that are defined in an array. People are not nearly as good as counting array elements as the processor. Then make these changed to the for loops:

// earlier code...
for (int i = 0; i < ELEMENTS(led); i++){
// more code...
  for (count ; count < ELEMENTS(led); count++){  // Not sure why the first expression is just count

Using the macro means that, if you change the number of elements in led[], all your for loops are automatically changed after you compile the code...much less error prone.

paulrind:
Why i<12 and count<14 ?

after playing around with it a bit, this is what seemed to work for me to keep the joystick movement in range of the LED line without going passed

econjack:
Put this as the first line at the top of your program, outside of setup()

#define ELEMENTS(x)  (sizeof(x) / sizeof(x[0]))

This is a preprocessor macro that determines the number of elements that are defined in an array. People are not nearly as good as counting array elements as the processor. Then make these changed to the for loops:

// earlier code...

for (int i = 0; i < ELEMENTS(led); i++){
// more code...
  for (count ; count < ELEMENTS(led); count++){  // Not sure why the first expression is just count




Using the macro means that, if you change the number of elements in *led[]*, all your *for* loops are automatically changed after you compile the code...much less error prone.

I'll give this a shot and report back, thanks.

econjack:
Put this as the first line at the top of your program, outside of setup()

#define ELEMENTS(x)  (sizeof(x) / sizeof(x[0]))

This is a preprocessor macro that determines the number of elements that are defined in an array. People are not nearly as good as counting array elements as the processor. Then make these changed to the for loops:

// earlier code...

for (int i = 0; i < ELEMENTS(led); i++){
// more code...
  for (count ; count < ELEMENTS(led); count++){  // Not sure why the first expression is just count




Using the macro means that, if you change the number of elements in *led[]*, all your *for* loops are automatically changed after you compile the code...much less error prone.

I Implemented what you said, thank you its much cleaner and clearer:

#define ELEMENTS(x)  (sizeof(x) / sizeof(x[0]))

int led[] = {2,3,4,5,6,7,8,9,10,11,12,13};

void setup() {
  Serial.begin(9600);

for (int i = 0; i < ELEMENTS(led); i++){
   pinMode(led[i], OUTPUT);
   digitalWrite(led[i], LOW);
  }
}

void loop() {
  int xAxis = analogRead(A0);
  int yAxis = analogRead(A1);
  int sizeSelector = analogRead(A2);
  //int count = led[0];

  sizeSelector = map(sizeSelector, 0, 1020, 4, 1);
  
  Serial.println(xAxis);
  Serial.print(sizeSelector);
  
if (sizeSelector == 1){
  xAxis = map(xAxis, 0, 1020, 0, 11);
  for (int i = 0; i < ELEMENTS(led); i++){
   digitalWrite(led[xAxis], LOW);
   delay(1);
   digitalWrite(led[xAxis], HIGH);
  }
}
}

The end result is still exactly the same though. https://gfycat.com/TalkativeMasculineDinosaur

The LOW led is still getting some current for some reason.

MY code wasn't meant to solve your initial problem, but rather to solve a problem you didn't even realize you had. As to your problem, consider:

  for (int i = 0; i < ELEMENTS(led); i++){
   digitalWrite(led[xAxis], LOW);
   delay(1);
   digitalWrite(led[xAxis], HIGH);
  }

Are your eyes good enough to sense a 1 millisecond change in an LED? Or will your persistence of vision have an impact on what you see? What would happen if you changed the delay to 500 milliseconds?

That loop ensures every LED is on most of the time, at the end of each loop it
leaves it on and steps to the next LED.