Closed dcmcshan closed 2 weeks ago
Yes the display driver supports using PWM. It does so using a 0.0 to 100.0 scale which gets mapped to the 0 to 65535 range. I never considered the PWM working in reverse where 0 is full on and the higher the number the dimmer it gets. That's rather backwards.
You do have the ability to override the display drivers handling by using something along the lines of...
import st7735
class ST7735R_Red(st7735.ST7735R_Red):
def set_backlight(self, value):
self._backlight_pin.duty_u16(int(((value * -1023.0) / 100.0) + 1023.0)) # NOQA
display = ST7735R_Red(
data_bus=self.display_bus,
display_width=80,
display_height=160,
reset_pin=PIN_LCD_RESET,
reset_state=st7735.STATE_LOW,
power_on_state=st7735.STATE_HIGH,
backlight_pin=PIN_LCD_BACKLIGHT,
backlight_on_state=st7735.STATE_PWM,
offset_x=26,
offset_y=1,
color_space=lv.COLOR_FORMAT.RGB565,
rgb565_byte_swap=True,
color_byte_order=st7735.BYTE_ORDER_BGR
)
and if you are using the new style display drivers...
import st7735
class ST7735(st7735.ST7735):
def set_backlight(self, value):
self._backlight_pin.duty_u16(int(((value * -1023.0) / 100.0) + 1023.0)) # NOQA
display = ST7735(
data_bus=self.display_bus,
display_width=80,
display_height=160,
reset_pin=PIN_LCD_RESET,
reset_state=st7735.STATE_LOW,
power_on_state=st7735.STATE_HIGH,
backlight_pin=PIN_LCD_BACKLIGHT,
backlight_on_state=st7735.STATE_PWM,
offset_x=26,
offset_y=1,
color_space=lv.COLOR_FORMAT.RGB565,
rgb565_byte_swap=True,
color_byte_order=st7735.BYTE_ORDER_BGR
)
display.init(st7735.TYPE_R_RED)
That will make the backlight work properly in your use case.
Does the display driver support backlight pwm? my LCD backlight is full brightness at 0, and dark at 1023. I'd like to be able to dim it. I can do this directly on the pin, but I'd like to do it through the driver, if it supports it.