As an analog guy you might appreciate the simplicity of this -
Basically this takes a V value off a pin and converts it to a pulse width to
control a LEDs brightness.
First instruction, 2'ond block, creates a variable, AtoDval.
The first instruction in forever loop reads analog pin value, its range is 0 - 1023
for a 0 - 5V input and puts it in variable AtoDval.
The second instruction writes that variable out to a digital pin which sets the PWM duty cycle
with the V value you read from pin.
Thats it to create a variable brightness control.
There is a slight complication in that analog to digital value is 10 bits (0 - 1023) and
PWM range of duty cycle setting is 8 bits (0 - 255), thats why the /4 is there, so what
gets written to PWM is most significant top 8 bits of the V value on the input pin.
Think using a pot on the analog pin to create the variable voltage.
Anyways many examples on web, I use them and then mod them often.
Regards, Dana.