Part of your problem may be that analogRead returns a ten bit number, but analogWrite takes an eight bit number.