Ping sensor and LED lightbox

Here is my code:

You need to post all of your code. From that snippet, we have no way of knowing whether you are getting any distance readings, or if they are anywhere near correct. A distance reading takes time. If you are not allowing for that, you will not get decent data. You typically do not need to average ping sensor readings. Simply ignore a value if it is radically different from a previous reading.

 brightness = brightness++;

brightness++; is shorthand for brightness = brightness + 1; Your statement, then, is equivalent to

brightness = brightness = brightness + 1;

I think you should be able to compare these two statements, and figure out what to remove from yours.

Thought it would be within my simple abilities obviously not.

You haven't told us what this code does that you do not want, or what it does not do that you want it to do. Without that information, it is hard to tell you how to change it to do what you want.