Problem to regulate the speed

Hi,

My projet consists in making turn a motor and with the possibility to control speed and state of the motor. I have the electronic circuit. You also have the following program. My only problem is to regulate the motor with the potentiometer. Could help me please???

 int PushButton_pin = 7; // Push button Pin
int Motor_Pin1 = 10; // pin 2 on L293D
int Motor_Pin2 = 9; // pin 7 on L293D
int Enable = 11; // pin 1 on L293D
int PotPin = A0;
int MotorSpeed;

void setup() {
    Serial.begin(19200);
    pinMode(PushButton_pin, INPUT);  //Setting the push button as the input pin
    //Setting the motor pins and the enable pin as the output pin
    pinMode(Motor_Pin1, OUTPUT);
    pinMode(Motor_Pin2, OUTPUT);
    pinMode(Enable, OUTPUT);
    digitalWrite(Enable, HIGH);  //Making the enable pin high to run the motor
}

void loop() {
    if (digitalRead(PushButton_pin) == HIGH) {  //Checking the state of the push button
        //Making one pin high and other low to run the motor
        digitalWrite(Motor_Pin1, LOW);
        digitalWrite(Motor_Pin2, HIGH);
    }
    //if the state of the push button will be low then the motor will not move
    else {
      //Making both the motor pins low to keep the motor at rest if the push button is not pressed.
        digitalWrite(Motor_Pin1, LOW);
        digitalWrite(Motor_Pin2, LOW);
    }
   
    MotorSpeed=map(analogRead(PotPin), 0,1023,100,254);
    //MotorSpeed = analogRead(PotPin)/4;
    Serial.println(MotorSpeed);
    digitalWrite(Enable, MotorSpeed);
}

a794531460bbb63c2005a2e942da4c5048850589.png

Your button will work if you set the pinMode for the button input pin to INPUT_PULLUP. The button will be active LOW, meaning that the button reads HIGH when not pressed and LOW when pressed. Adjust the code accordingly. You don’t need the 220 Ohm resistor. Without the pullup the pin is “floating” in an indeterminate state. You may need to debounce the push button switch. That can be done in software or hardware debounce with a 0.1uf cap across the switch.

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.
For posting images see:-
image guide

The pot on the schematic and the Fritzing physical diagram crap are wired up differently. The one on the schematic will not work.