Created
June 20, 2023 20:34
-
-
Save io41/4e19839560e5231cd4a711cd9182ad64 to your computer and use it in GitHub Desktop.
Circuit Python Example ST7735 LCD backlight fading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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