Softstart/softstop code

Busy building code for controlling motorspeed.
My wish is to run code that can change pwm speed whit softstart and softstop.


changing speed over time like the straight line is possible by
speed=50
newspeed=75
tempspeed=speed+1
this loop continues till tempspeed is 75.
disadvanges of this code is that it takes to long to get there

or like the other line you use
FOR command ```
for (initialization; condition; increment)

disadvanges of this one it only slowly speed up and its a loop

But i want to get it like red line, (up but also the same downwards)
didn't find a correct code of example for

So is there a good way to get some code to get to there. 
that goes from speed to newspeed

Why should it take too long? It depends on your sketch how often you increase the speed and whether you increase only by 1 or make bigger steps to increase faster.

So you want to start a move slowly, accelerate to full speed (whatever that is) and then decelerate to a stop. Is the goal to reach a particular destination position? How do you measure your position? Since you mention PWM it appear you are using something like a DC motor. Is that true?

Conceptually, you can use a proportional control algorithm, i.e. use the difference between the current value and the target value to increase/decrease the speed increments.

Let Curr be the current speed, Start the beginning speed, Target the target speed, and Delta by how much to increase speed. Increase Delta if Curr < (Target-Start)/2, and force Delta=0 if Current >= Target.

Example: Start=0, Target=10, Delta=0
Curr=Start, (Target-Start)/2=5
Curr:=0, Diff=10, Delta=1 (Curr<5)
Curr= 1, Diff=9, Delta=2 (Curr<5)
Curr=3, Diff=7, Delta=3 (Curr<5)
Curr=6, Diff=4, Delta=2 (Curr>5)
Curr=8, Diff=2, Delta=1 (Curr>5)
Cur=9, Diff=1, Delta=1 (Curr>5)
Curr=10, Diff=0, Delta=0

This only demonstrates the principle, you may have to deal w ith overshoots by setting Delta to a negative value.

Search: "S curve acceleration".