Skip to content

Instantly share code, notes, and snippets.

@io41
Created June 20, 2023 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io41/4e19839560e5231cd4a711cd9182ad64 to your computer and use it in GitHub Desktop.
Save io41/4e19839560e5231cd4a711cd9182ad64 to your computer and use it in GitHub Desktop.
Circuit Python Example ST7735 LCD backlight fading
import board
import time
import pwmio
print("Hello world!")
class LCD:
_led = None
_led_max = 65535
@property
def led(self):
if self._led is None:
self._led = pwmio.PWMOut(board.GP25, frequency=1000, duty_cycle=65536)
return self._led
def backlight(self, value):
"""Set backlight brightness in percent"""
new_value = min((self._led_max * value // 100, self._led_max))
self.led.duty_cycle = new_value
def main():
lcd = LCD()
while True:
for i in range(101):
lcd.backlight(i)
time.sleep(0.01)
for i in range(100, 0, -1):
lcd.backlight(i)
time.sleep(0.01)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment