Automatic level adjustment

I have tried these inside the void loop():

The first one won't even compile. There is a missing ;. Depending on how L is defined, it may be being set to 0 on every pass through loop, so incrementing by one on each pass will result in getting to 1 each time. This appears to coincide with your symptoms, so the problem lies outside this snippet.

Any comments or help are greatly appreciated.

Post ALL of your code.