Corrolation between Distance and RGB value

I have a really cool idea for a project but a lack of knowledge in a very key part of said project. How would I make it so that for say every 1/2 centimeter the value of the red pin would increase by 5. If anyone has any tips or advice I will be happy to listen.

That key part would be expressing the question clearly. What do you mean ‘increase by 5’ ? What sensor?

Then toss some of your pseudo-code so we might understand more. And a schematic/block diagram (not Fritzy)

First be aware that analogWrite() which I guess is what you're talking about, only goes as high as 255. There's not an infinite number of jumps available. At 5 per 1/2 cm, that's 51 jumps of 1/2 cm, giving you a working range of 25cm; is that what you have in mind?

So perhaps you envisage an item further away that 25cm, and the led is off. As it approaches 25 it stays off. Then at 25cm it comes on dim, and as the object gets ever closer the led gets brighter, until when it's up against the sensor (if the sensor reads that close, anyway) the led's full on?

Is that the idea?