RGB flashing color between while loops

Grumpy_Mike:
This is because the last iteration of the while loop starts with a value of rn being 255

Agreed, the OP could use for() loops for this instead of while() loops, or assign the loop control variable back to zero before the while() loop.

Grumpy_Mike:
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.

Mike, won't the * and / get evaluated in left to right order because they have equal precedence? Hence my suggestion of casting to long so that the intermediate result of the * did not overflow, and the / would then give a useable result. (I though this overflow was causing the effect the OP is describing, I did not spot the more obvious answer as you did!)