RGB flashing color between while loops

t briefly flashes the color that was just dimmed.

This is because the last iteration of the while loop starts with a value of rn being 255. You then increment rn making it 256 which when you apply to PWM is the equivalent of zero. So make all the while loops just less than 255 not less than or equal to 255.

You are going to add an analog reading to this and at the moment it is commented out. But when it is not the your lines like

r = rn * audio/1024;

Are going to return zero because the variable audio is an integer, and any integer divided by a larger integer will return zero. You need to look at floating point variables at this stage.