Button timer with PWM output

Couldn't wait to try it after work, this is what I did. I cant believe I made it work haha. I also made the switching frequency 8Khz and it got rid of my IGBT noise (just had to upscale my millis now to match previous durations). Thank you for helping me. this is a great community and I definitely will have some more upcoming projects.

/*
  https://forum.arduino.cc/t/button-timer-with-pwm-output/1419547/
*/



#define BTN_PIN 2
#define LED_PIN 5
#define POT_PIN A0
#define POT2_PIN A1
#define POT3_PIN A2


unsigned long lastBtn;
unsigned long btnDebounce = 50;
byte btnState = HIGH;


unsigned long ledStart;
unsigned long ledRunTime = 1000;

enum StatesSystem {
  state_Idle,
  state_Wait,
  state_Run
};

StatesSystem sysState = state_Idle;

unsigned long waitStart;
unsigned long waitTime = 1000;

void setup() {
  Serial.begin(115200);
  TCCR0B = TCCR0B & 0b11111000 | 0x02;
  pinMode(BTN_PIN, INPUT_PULLUP);

}

void loop() {

  unsigned long now = millis();

  int v;

  v = analogRead(POT2_PIN);
  waitTime = map(v, 0, 1023, 10, 5000);


  if (now - lastBtn >= btnDebounce) {
    byte b = digitalRead(BTN_PIN);
    if (b != btnState) {
      lastBtn = now;
      btnState = b;
      if (b == HIGH) {
        //press and release
        if (sysState == state_Idle) {
          sysState = state_Wait;
          waitStart = now;
        }
      }
    }
  }
  
  v = analogRead(POT3_PIN);
  ledRunTime = map(v, 0, 1023, 5, 2000);
     

  switch (sysState) {
    case state_Wait:
      if (now - waitStart >= waitTime) {
        sysState = state_Run;
        ledStart = now;
      }
      break;
    case state_Run:
      if (now - ledStart >= ledRunTime) {
        //stop
        sysState = state_Idle;
        analogWrite(LED_PIN, 0);
      } else {
        //led is active..
        v = analogRead(POT_PIN);
        v = map(v, 0, 1023, 0, 255);
        analogWrite(LED_PIN, v);
      }
      break;
  }
}