Edit: This is the python script that dims the backlight up and down.
$ sudo pigpiod
$ python3
import pigpio
import time
gpio = pigpio.pi()
gpio.set_mode(18, pigpio.OUTPUT)
#gpio.set_mode(18, pigpio.ALT5) - behaves the same
def dim_up():
for x in range(2,200):
gpio.set_PWM_dutycycle(18, x)
print('level =', x)
time.sleep(0.01)
def dim_down():
for x in range(200,1,-1):
gpio.set_PWM_dutycycle(18, x)
print('level =', x)
time.sleep(0.01)
def cycle_dim():
while True:
dim_up()
dim_down()
cycle_dim()
This works fine and dims up and down smoothly until you change either range
to include 1
or 0
in the range. Then, the first time before it hits those numbers, it works fine, then after those numbers it is either full on or full off, no range in between.