TSL235R inconsistent output

Check your variable scope. You should not reinitialize values you want to save. In fact, I'd try to minimize initializing values.