Changing pwm value in function of an other valueo

Hi guys,

I m to ask for your help once again.

I made a wattmeter for monitoring of consuption of a brushless motor and everything works fine.

I control the ESC via manual PWM signal

Now i would like to get a value of PWM in funcion of analog read of watt sensor

Example:

Automatic acceleration writing PWM signal on pin 11 (1,2,3,4...10....50...2000...255), at the same moment reading the value of the analog pin for wattmeter and change the value of PWM tryin to make costant the value po analog pin for wattmeter that i chiose

Something like this

Value o range i chiose : 30-35 watt

Read anog pin 10 watt, and accelerate till the value will be between 30 and 35 and decelerate in case will go over

Thank you

I think it would be a good idea to have a look at PID control.
You can find a bit about that in the playground, and 'm sure it has been discussed here on the forums.