Problem with resetting led state after countdown

Hello,

I am quite new to arduino and am having problems writing a sketch for a countdown that is started when a switch is flicked, and is restarted when the switch is flicked to off and then back on. I am not sure whether my description is of any help so here is the code:

int delayPeriodOff = 1000;
const int delayPeriodOn = 50;
const int ledPin = 12;
const int switchPin = 7;

int val= 0;


void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(switchPin, INPUT);
}

void loop() {
    val = digitalRead(switchPin);
    
  if (val == HIGH) {
    countDown();
    }
    
   if (val == LOW) {
      blinkLed();
    }
    
}

void blinkLed () {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
}

void countDown () {
    digitalWrite(ledPin, HIGH);
    delay(delayPeriodOn);
    digitalWrite(ledPin, LOW);
    delay(delayPeriodOff);
     delayPeriodOff = delayPeriodOff-20;   
         if (delayPeriodOff <= 0) {
          ledOn ();
          }     
   }

void ledOn () {
    while(val == HIGH, delayPeriodOff <= 0);
      digitalWrite (ledPin, HIGH);
      delay (INFINITY);
}

As stated, I am new to arduino and programming in general and might have missed any number of obvious errors. I would appreciate any and all help.

thanks
Apower101

void ledOn () {
    while(val == HIGH, delayPeriodOff <= 0);
      digitalWrite (ledPin, HIGH);
      delay (INFINITY);
}

Take a really close look at the “while”

from what I understand of while commands, which isn't very much, I have told the arduino to keep the light on forever when the delay period is equal to or less than 0, until the switch switch flipped. Is this wrong? should I replace the while with an if? Because I tried that and it didn't work. should I put a do in front of the digitalWrite?

Tell me what you think the comma does in your while
Then tell me about the semicolon

does it not separate the two conditions that need to be fulfilled to leave the while command?

You're absolutely correct - it doesn't.

Is this wrong?

Yes. The comma operator is not the && operator.

Of course, even correcting that, you never assign a new value to val, so it it's HIGH to start with, it will never be a factor in the while loop ending.