diff display.py @ 1:5a93179ccae9

7key code
author drewp@bigasterisk.com
date Thu, 11 May 2023 15:07:10 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.py	Thu May 11 15:07:10 2023 -0700
@@ -0,0 +1,45 @@
+import time
+import random
+from machine import Pin, PWM, SPI
+from ST7735 import TFT, TFTColor
+from sysfont import sysfont
+
+
+class Display:
+    def __init__(self):
+        self.lcd_backlight = PWM(Pin(17), freq=20000, duty=1023)
+        self.backlight_level = 0  # to 100
+        self.spi = SPI(1,
+                       baudrate=20000000,
+                       polarity=0,
+                       phase=0,
+                       sck=Pin(5),
+                       mosi=Pin(18))
+        self.tft = TFT(
+            self.spi,
+            aDC=19,
+            aReset=16,  # not connected
+            aCS=21)
+        self.tft.rotation(2)
+        self.tft.initr()
+        self.tft.rgb(True)
+
+        self.tft.fill(TFT.BLACK)
+        # for x in range(0, self.tft.size()[0], 6):
+        #     self.tft.line((0, 0), (x, self.tft.size()[1] - 1),
+        #                   TFTColor(random.randrange(0, 256),
+        #                            random.randrange(0, 256),
+        #                            random.randrange(0, 256)))
+    def startupText(self, row, msg):
+        y1 = (row + 1) * 10
+        self.tft.fillrect((0, y1), (128, 10), TFT.BLACK)
+        self.tft.text((3, y1), msg, TFT.WHITE, sysfont)
+
+    def backlight(self, new, step_sec=0.005):
+        v = self.backlight_level
+        while v != new:
+            v = v + (-1 if v > new else (1 if v < new else 0))
+            self.lcd_backlight.duty(v * 10)
+            self.backlight_level = v
+            time.sleep(step_sec)
+