Programming voltage on Arduino MEGA output?

Hi!

I have a motor+motorcontroller wich can be steered with a 0 to 5V signal.

0V (or close to it) is forward.
2.5V is still.
5V is backward.

I have the 5V signal out from the Arduino, so I can go one direction,
and the motorcontroller can give a constant 2.5V signal to itself så that it stands still when its supposed to.

Can i make my 5V output change to for example 0.1V when i press the forward button?
What programcode do I need? :o
And what could be worth thinking about regarding this?

Best regards U.

You need a add an RC low pass filter onto a PWM pin, and use analogWrite to set the duty cycle of the
PWM pin to control the output voltage. Try 1k and 47uF. Googling "RC lowpass filter" should help.

Read the reference on analogWrite() and PWM for a decent explanation and more understanding.