Raspberry Pi practice problem · LEDs & PWM
Even steps for the eye
MediumBudget $2Python · gpiozero
Our eyes are far more sensitive to changes in dim light than in bright light, so 0 %, 25 %, 50 %, 75 %, 100 % duty looks like a big jump followed by tiny ones. The fix is gamma correction: for perceived level k / 4, use the duty
duty = (k / 4) ** 2.2
A PWMLED on GPIO18 shows the five levels k = 0, 1, 2, 3, 4, each for 0.5 s starting at 0 s, then starts again at k = 0 (at 2.5 s), forever. The test expects duties of about 0, 0.047, 0.218, 0.531, 1 (within ±0.01).