conflicting code? clarification

I posted here the other day. My problem was with addressable LED strips and range sensors.
concept is the further your hand is away from the range sensor the more LEDs in the strip light up.
however my code only allows this to work in one direction. As I raise my hand away from the sensor the LEDs illuminate as desired but are then "stuck" lowering my hand does not tell them to turn back off.

Admittedly, I am not a programmer. I only posses the most basic idea of what I'm doing and I do not yet really "grasp" all the syntax of a "neat and cohesive" script.

That being said, I think my problem is here:

  for(i=0; i<v;) {
    if (i<v, i++);
    strip.setPixelColor(i,0,0,175);
    if (i=v; i>0;) i--)
    strip.setPixelColor(i,0,0,0);
    strip.show();

Ill attach the complete code at the end; What im trying to say here is

v = value translated from the range sensor
i = the number of pixels in the strip or the "last pixel that is still illuminated"

if the value of 'v' is greater than the value of 'i' make 'v' equal to 'i' and illuminate the 'v' value of pixels.

if the value of 'v' is less than the value of 'i' make 'v' equal to 'i' and turn of the pixels no longer in the equation.

(now that we have checked both possible outcomes)

show the one that is relevant.

I think where im getting in trouble is when I try to redefine the v=0; i=0 stuff

here is the full code, try not to laugh

#include "LPD6803.h"

#define N_PIXELS  50  // Number of pixels in strand

const int pingPin = 7;

int dataPin = 2;
int clockPin = 3; 

  LPD6803 strip = LPD6803(50, dataPin, clockPin);

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

void loop() {
  uint8_t  i;
  int duration, v;
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  v = (duration/2) / 29.1;
  v = map(v,20,0,50,0);
  if (v <= 50) {
    Serial.println(v);}
    else
    v = 2;
    Serial.println(v);

  delay(50);

  for(i=0; i<v;) {
    if (i<v, i++)
    strip.setPixelColor(i,0,0,175);
    if (i=v, i>0) i--)
    strip.setPixelColor(i,0,0,0);
    strip.show();
    
  }
}

unsigned int Color(byte r, byte g, byte b)
{
  //Take the lowest 5 bits of each value and append them end to end
  return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<5 | (unsigned int)r & 0x1F);
}

Lots of things wrong.
Always use == in an if statement never a =

Dividing any int by 29.1 is just silly.

For loops need an index increment clause,you don't always have one.

Have a for loop that goes from 0 to the maximum number of pixels. If the loop index is below your required length of lights threshold then set it to your colour else set it to black that is off.

Get into the habit of writing very short programs to try out every new technique separately as you come to it. In this case (for example), IF clauses and FOR loops. That way you can more easily understand what is causing the problem or what you may have misundersttod about how to use the technique.

This is especially true if you are new to programming. When you become more experienced you will know to do it anyway.

...R

effectively you want to light up v pixels with the snippet.

simplest is to switch them all 50 on/off

for (int i = 0; i < N_PIXELS; i++) 
{
  if (i <= v) 
  {
    strip.setPixelColor(i, 0, 0, 175);
  }
  else 
  {
    strip.setPixelColor(i, 0, 0, 0);
  }
}
strip.show();

if you want to do this more efficiently and not want to do all 50 pixels every time
you need to remember the previous value of v,
in code you get something like this

for (int i = min(prevV, curV); i <= max(prevV, curV); i++) 
{
  if (prevV <= curV) 
  {
    strip.setPixelColor(i, 0, 0, 175);
  }
  else 
  {
    strip.setPixelColor(i, 0, 0, 0);
  }
}
prevV = curV
strip.show();

give it a try