help please, button fades light

newb here.
want to push or hold a button and fade an LED in brightness-increments of 15 up until 255, then down until 0, then up again etc.

works from reset, but after some iterations, cant tell why, fadeAmount doesn't flip or something, so instead of fading up then down then up etc., it fades up then jumps back to 0, or fades down then jumps back to 255.

short vid demonstrating problem:

tia. here's code:

const int buttonPin = 2;
const int ledPin = 9;

int buttonState;
int ledBrightness = 0;
int fadeAmount = 15;

long lastDebounceTime = 0;
long debounceDelay = 50;

void setup() {

pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {

analogWrite(ledPin, ledBrightness);

int reading = digitalRead(buttonPin);

if (reading != LOW) {
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
buttonState = reading;
}

if (reading != LOW) {
ledBrightness = ledBrightness + fadeAmount;
}

if (ledBrightness == 0 || ledBrightness == 210) {
fadeAmount = -fadeAmount;
}
delay(100);
}

What happens if ledBrightness ends up < 0 or > 210?

-br

210/15=14
how could it end up not 210 or 0?

Fair point. Perhaps it’s not an issue here (until you change the increment). Fortune favors those who use <= and >= defensively…

Another question: Isn’t this segment inverting fadeAmount every pass through the loop, whether or not it has been added to ledBrightness?

 if (reading != LOW) {
    ledBrightness = ledBrightness + fadeAmount;
  }
  
  if (ledBrightness == 0 || ledBrightness == 210) {
    fadeAmount = -fadeAmount;
  }

-br

changed to this. fixed the problem.
you rule br.

if (reading != LOW) {
ledBrightness = ledBrightness + fadeAmount;
if (ledBrightness <= 0 || ledBrightness >= 210) {
fadeAmount = -fadeAmount;
}

changed to this. fixed the problem.

Now, look at the compound operators, like +=, and embrace them.

    ledBrightness = ledBrightness + fadeAmount;

could be much shorter.