Tutorial - How to change firmware on 8u2

The problem seems to be with

sensorValue = analogRead(i);

sensorValue is a byte so its range is 0-255

then you map:

sensorValue = map(sensorValue, 0, 1024, 0, 255);

so sensorValue=255*255/1024=63

I hope this can help you