1. Use a timer interrupt and in thee Isr change a pwm generator duty cycle. Or 2. Use a timer and set up two compare channels with a fixed offset. In the compare Isr, advance the math points forward and then flip an output pin. You will see the brightness goes up and down, whose speed depends on the offset. No need for gamma correction.