Fix the problem I pointed out in my edit. Hint: which element of pwmVals are you assigning to brightness?