brightness and contrast

I was inspired by a menu on the net and I would like to adjust the brightness and contrast of my screen (HD44780) through this menu. how can I do this using 2 analog pins?
if you can give me the code already done would be even better.

You can adjust the contrast of the LCD display itself by replacing the potentiometer that is feeding pin 3 with a PWM signal.

You can adjust the brightness of the backlight by feeding a PWM signal to an appropriate transistor in the backlight anode or cathode lead (pin 15 or 16).

I have personally done neither so I can't help you with the code.

Don