A PWM Ramp up using a momentery button press

hi guys/gals

i was traling the interwebs looking for a pwm ramp that i can adapt to led’s and mosfet speed controllers
after a good few houers i found this bit of code

#define BUTTON 7
#define LED 9

int dir = 1;
int lum = 0;
boolean toggle = false;

void setup() {
  pinMode(BUTTON, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  if (digitalRead(BUTTON) == HIGH) {
    toggle = true;
    lum += dir;
    if ((lum >= 0) && (lum < 256))
      analogWrite(LED, lum);
    delay(20);
  } else { // toggle direction
    if (toggle) {
      dir = -1 * dir;
      toggle = false;
    }
  }
}

i gave it a go and it was almost doing what i wanted so anouther
two houres (im bad at the arduino language)
i managed to edit it to get a ramp that resets when the button is released

#define BUTTON 7
#define PWMOUT 9

int dir = 1;
int lum = 0;
boolean toggle = false;

void setup() {
  pinMode(BUTTON, INPUT);
  pinMode(PWMOUT, OUTPUT);
}

void loop() {
  if (digitalRead(BUTTON) == HIGH) {
    toggle = true;
    lum += dir;
    if ((lum >= 0) && (lum < 256)) // ramp min to max ,set (lum <)
                                   // to desierd level for max
      analogWrite(PWMOUT, lum);
    delay(150);// Ramp speed (suggest 1-150)
  } else { // reset out put to 0
    analogWrite(PWMOUT, lum = 0);
  }
}

so i thort i would put it on here to hopfully help some pepole

i will be adding fets and a dc motor soon will update with results