PWM fan speed control

While i was searching code for control my fan's speed with PWM i found this code. It is working partically but not working properly but i couldn't find what is wrong. I want that when i push any button that predefined fan speed will continously will work with that speed.

  #define PIN_MEMBRAN_RIGHT   13
  #define PIN_MEMBRAN_UP      12
  #define PIN_MEMBRAN_DOWN    11
  #define PIN_MEMBRAN_SELECT  10
  #define PIN_MEMBRAN_LEFT    9
  #define PIN_MEMBRAN_START   8
  
  uint8_t membran_pin_list[] = {
    PIN_MEMBRAN_UP,
    PIN_MEMBRAN_DOWN,
    PIN_MEMBRAN_RIGHT,
    PIN_MEMBRAN_LEFT,
    PIN_MEMBRAN_SELECT,
    PIN_MEMBRAN_START
  };
  
  #define PIN_FAN 6 
  int PushButtonInput_1 = 13;   // Push button - set PWM Fan speed %25
  int PushButtonInput_2 = 12;   // Push button - set PWM Fan speed %50
  int PushButtonInput_3 = 11;   // Push button - set PWM Fan speed %75
  int PushButtonInput_4 = 9;    // Push button - set PWM Fan speed  %100
  
  void setup() {
    pinMode(PIN_FAN, OUTPUT);
    digitalWrite(PIN_FAN, HIGH);
    pinMode(PushButtonInput_1,INPUT_PULLUP);
    pinMode(PushButtonInput_2,INPUT_PULLUP);
    pinMode(PushButtonInput_3,INPUT_PULLUP);
    pinMode(PushButtonInput_4,INPUT_PULLUP);
  }
  
  void loop() {
   //-----------------25%----------------------
   if(digitalRead(PushButtonInput_1)==HIGH){
     analogWrite(PIN_FAN, 64);
     //Serial.print(PushButtonInput_1);
   }
   
   //----------------50%---------------------
   if(digitalRead(PushButtonInput_2)==HIGH){
    analogWrite(PIN_FAN, 128);
   }
   
   //------------------75%-----------------------
   if(digitalRead(PushButtonInput_3)==HIGH) {
     analogWrite(PIN_FAN, 192);
   }
   //---------------------------------------------

   //------------------100%-----------------------
   if(digitalRead(PushButtonInput_4)==HIGH){
     analogWrite(PIN_FAN, 255);
   }
   //---------------------------------------------
}

Hi,
from what I understand from your code, the buttons are connected between the pins (13,12,11 and 9) and the GND. Correct?
If so, change all lines lines
if(digitalRead(PushButtonInput_X)==HIGH){
to
if(digitalRead(PushButtonInput_X)==LOW){

Hi,
from what I understand from your code, the buttons are connected between the pins (13,12,11 and 9) and the GND. Correct?

Yes. My membran has 7 buttons but i just defined 4 of them to control speed.

When i changed the code like this i got the result that i want.

void loop() {
   //-----------------25%----------------------
   if(digitalRead(PushButtonInput_1)==LOW){
     analogWrite(PIN_FAN, 64);
     //Serial.print(PushButtonInput_1);
   }
   
   //----------------50%---------------------
   if(digitalRead(PushButtonInput_2)==LOW){
    analogWrite(PIN_FAN, 128);
   }
   
   //------------------75%-----------------------
   if(digitalRead(PushButtonInput_3)==LOW) {
     analogWrite(PIN_FAN, 192);
   }
   //---------------------------------------------

   //------------------100%-----------------------
   if(digitalRead(PushButtonInput_4)==LOW){
     analogWrite(PIN_FAN, 255);
   }
   //---------------------------------------------
}

I want to ask 1 more question.
If i want to run my fan with %25 of it's power dividing 255/4=64 than, analogWrite(PIN_FAN, 64);
is this right ?

Hi,
theoretically yes;
but applying 25% of the pulse time to HIGH on the fan will make it spin at 25% of its speed?

It is spinning, it worked but i am sure, it is not the %25 of it's total power. It is still working loudly but more less than %100. I want that it works with it's minimum capacity.