arduino pwm variable motor speed controler

hello I just start with arduino . I made a electric scooter but my pwm controler broke and I heard that you could make one with an arduino my part that i have is

-arduino mega

-mosfet irfp150n

-motor is my1016 350w 24-36v

I am using a 42V-36V power suply (10 cell lipo battery )

those guy (incroyable experience ) made a arduino pwm but i dont know why when i’ve tried it it doesnt work here is the link for the project that they made Facebook

in general in their program there is a variable flexiblility of driving : it make the aceleration less violent and economise the battery , there is also a fail safe for the to much violent aceleration and finaly there is the duty cycle of pwm . i would like to keep all of those feature bu if the fail safe if what is causing it to not work could you make a code that work with the flexibility of driving control .

these guy talk french so the code explanation might be weired because i translate it

this is the code with the flex driving
/* PWM
for DC motor with flexible drive control (2 potentiometers).
1.4, Incroyables Expériences */

void setup() // Boucle d’initialisation.
{
pinMode(3, OUTPUT); // Pin 3 is set as digital output.
}

float r=0; // Initialization of the actual cyclic ratio to 0.
float s=30; // Initialization of driving flexibility.
int a=0; // Initialization of the requested duty cycle to 0.
int b=0; // Initialization of the requested duty cycle memory.
int c=70; // Initialization of the security threshold (the higher it is, the less security is effective).

void loop() { // Boucle principale

analogWrite(3,r/1023*254); // Creation of pwm.
a=analogRead(0); // Reading the requested duty cycle.
s=analogRead(1); // Reading of required driving flexibility.

if(a>b+c){ // Verification of acceleration too sudden (of voluntary origin or not).
digitalWrite(3,LOW); // Immediate stop of the engine.
while(a>c){ // waiting of a very low cyclic ratio to restart.
a=analogRead(0); // Continuous reading of the requested duty cycle.
}
}
b=a; // Storing the requested duty cycle.

if(a>r){ //Verification of the desired duty cycle growth.
delay(20); // Delay responsible for driving flexibility.
r=r+s/20+2; // Empirical calibration of driving flexibility.
}
if(a<r){ // Verification of the decay of the requested duty cycle.
r=a; // Immediate reduction of the actual cyclic ratio if necessary.
}

}

this one is without the flex drive

(not translate )

/* PWM pour moteur à courant continu avec souplesse de conduite permanente (1 potentiomètre).
Version 1.4, Incroyables Expériences */

void setup() // Boucle d’initialisation.
{
pinMode(3, OUTPUT); // Broche 3 réglée comme sortie numérique.
}

float r=0; // Initialisation du rapport cyclique réel à 0.
float s=7; // Initialisation et choix de la souplesse de conduite (permanente).
int a=0; // Initialisation du rapport cyclique demandé à 0.
int b=0; // Initialisation de la mémoire du rapport cyclique demandé.
int c=70; // Initialisation du seuil de sécurité (plus il est élevé, moins la sécurité est efficace).

void loop() { // Boucle principale

analogWrite(3,r/1023*254); // Création du PWM.
a=analogRead(0); // Lecture du rapport cyclique demandé.

if(a>b+c){ // Vérification d’une accélération trop brutale (d’origine volontaire ou non).
digitalWrite(3,LOW); // Arrêt immédiat du moteur.
while(a>c){ // Attente d’un rapport cyclique très faible pour redémarrer.
a=analogRead(0); // Lecture continue du rapport cyclique demandé.
}
}
b=a; // Mémorisation du rapport cyclique demandé.

if(a>r){ // Vérification de la croissance du rapport cyclique demandé.
delay(20); // Délai responsable de la souplesse de conduite.
r=r+s; // Calibrage empirique de la souplesse de conduite.
}
if(a<r){ // Vérification de la décroissance du rapport cyclique demandé.
r=a; // Diminution immédiate du rapport cyclique réel le cas échéant.
}

}

does if they use a arduino nano and im using a mega it could be this the problem thank a lot for the one who respond me ( :

olivier is my name and im 13 years old