From f49307b22e3cb2c801065df2f5ae64dbf5c83e33 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Mon, 1 Nov 2021 18:18:07 +0000 Subject: [PATCH] Update examples get gif, image, scrolling-text and shapes examples working with Display HAT Mini --- examples/gif.py | 44 +++++++++++++++++++++++++++----------- examples/image.py | 42 ++++++++++++++++++++++++++---------- examples/scrolling-text.py | 42 ++++++++++++++++++++++++++---------- examples/shapes.py | 42 ++++++++++++++++++++++++++---------- 4 files changed, 125 insertions(+), 45 deletions(-) diff --git a/examples/gif.py b/examples/gif.py index 8fd7405..8ce7c0a 100755 --- a/examples/gif.py +++ b/examples/gif.py @@ -22,6 +22,7 @@ * square - 240x240 1.3" Square LCD * round - 240x240 1.3" Round LCD (applies an offset) * rect - 240x135 1.14" Rectangular LCD (applies an offset) + * dhmini - 320x240 2.0" Display HAT Mini """.format(path=sys.argv[0])) sys.exit(1) @@ -32,18 +33,37 @@ except IndexError: display_type = "square" -# Create TFT LCD display class. -disp = ST7789.ST7789( - height=135 if display_type == "rect" else 240, - rotation=0 if display_type == "rect" else 90, - port=0, - cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT - dc=9, - backlight=19, # 18 for back BG slot, 19 for front BG slot. - spi_speed_hz=80 * 1000 * 1000, - offset_left=0 if display_type == "square" else 40, - offset_top=53 if display_type == "rect" else 0 -) +# Create ST7789 LCD display class. + +if display_type in ("square", "rect", "round"): + disp = ST7789.ST7789( + height=135 if display_type == "rect" else 240, + rotation=0 if display_type == "rect" else 90, + port=0, + cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT + dc=9, + backlight=19, # 18 for back BG slot, 19 for front BG slot. + spi_speed_hz=80 * 1000 * 1000, + offset_left=0 if display_type == "square" else 40, + offset_top=53 if display_type == "rect" else 0 + ) + +elif display_type == "dhmini": + disp = ST7789.ST7789( + height=240, + width=320, + rotation=180, + port=0, + cs=1, + dc=9, + backlight=13, + spi_speed_hz=60 * 1000 * 1000, + offset_left=0, + offset_top=0 + ) + +else: + print ("Invalid display type!") # Initialize display. disp.begin() diff --git a/examples/image.py b/examples/image.py index c2a5237..353502c 100755 --- a/examples/image.py +++ b/examples/image.py @@ -19,6 +19,7 @@ * square - 240x240 1.3" Square LCD * round - 240x240 1.3" Round LCD (applies an offset) * rect - 240x135 1.14" Rectangular LCD (applies an offset) + * dhmini - 320x240 2.0" Display HAT Mini """.format(sys.argv[0])) sys.exit(1) @@ -30,17 +31,36 @@ display_type = "square" # Create ST7789 LCD display class. -disp = ST7789.ST7789( - height=135 if display_type == "rect" else 240, - rotation=0 if display_type == "rect" else 90, - port=0, - cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT - dc=9, - backlight=19, # 18 for back BG slot, 19 for front BG slot. - spi_speed_hz=80 * 1000 * 1000, - offset_left=0 if display_type == "square" else 40, - offset_top=53 if display_type == "rect" else 0 -) + +if display_type in ("square", "rect", "round"): + disp = ST7789.ST7789( + height=135 if display_type == "rect" else 240, + rotation=0 if display_type == "rect" else 90, + port=0, + cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT + dc=9, + backlight=19, # 18 for back BG slot, 19 for front BG slot. + spi_speed_hz=80 * 1000 * 1000, + offset_left=0 if display_type == "square" else 40, + offset_top=53 if display_type == "rect" else 0 + ) + +elif display_type == "dhmini": + disp = ST7789.ST7789( + height=240, + width=320, + rotation=180, + port=0, + cs=1, + dc=9, + backlight=13, + spi_speed_hz=60 * 1000 * 1000, + offset_left=0, + offset_top=0 + ) + +else: + print ("Invalid display type!") WIDTH = disp.width HEIGHT = disp.height diff --git a/examples/scrolling-text.py b/examples/scrolling-text.py index a5db873..becaded 100755 --- a/examples/scrolling-text.py +++ b/examples/scrolling-text.py @@ -24,6 +24,7 @@ * square - 240x240 1.3" Square LCD * round - 240x240 1.3" Round LCD (applies an offset) * rect - 240x135 1.14" Rectangular LCD (applies an offset) + * dhmini - 320x240 2.0" Display HAT Mini """.format(sys.argv[0])) try: @@ -38,17 +39,36 @@ # Create ST7789 LCD display class. -disp = ST7789.ST7789( - height=135 if display_type == "rect" else 240, - rotation=0 if display_type == "rect" else 90, - port=0, - cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT - dc=9, - backlight=19, # 18 for back BG slot, 19 for front BG slot. - spi_speed_hz=80 * 1000 * 1000, - offset_left=0 if display_type == "square" else 40, - offset_top=53 if display_type == "rect" else 0 -) + +if display_type in ("square", "rect", "round"): + disp = ST7789.ST7789( + height=135 if display_type == "rect" else 240, + rotation=0 if display_type == "rect" else 90, + port=0, + cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT + dc=9, + backlight=19, # 18 for back BG slot, 19 for front BG slot. + spi_speed_hz=80 * 1000 * 1000, + offset_left=0 if display_type == "square" else 40, + offset_top=53 if display_type == "rect" else 0 + ) + +elif display_type == "dhmini": + disp = ST7789.ST7789( + height=240, + width=320, + rotation=180, + port=0, + cs=1, + dc=9, + backlight=13, + spi_speed_hz=60 * 1000 * 1000, + offset_left=0, + offset_top=0 + ) + +else: + print ("Invalid display type!") # Initialize display. disp.begin() diff --git a/examples/shapes.py b/examples/shapes.py index 350f547..cd751be 100755 --- a/examples/shapes.py +++ b/examples/shapes.py @@ -20,6 +20,7 @@ * square - 240x240 1.3" Square LCD * round - 240x240 1.3" Round LCD (applies an offset) * rect - 240x135 1.14" Rectangular LCD (applies an offset) + * dhmini - 320x240 2.0" Display HAT Mini """.format(sys.argv[0])) try: @@ -28,17 +29,36 @@ display_type = "square" # Create ST7789 LCD display class. -disp = ST7789.ST7789( - height=135 if display_type == "rect" else 240, - rotation=0 if display_type == "rect" else 90, - port=0, - cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT - dc=9, - backlight=19, # 18 for back BG slot, 19 for front BG slot. - spi_speed_hz=80 * 1000 * 1000, - offset_left=0 if display_type == "square" else 40, - offset_top=53 if display_type == "rect" else 0 -) + +if display_type in ("square", "rect", "round"): + disp = ST7789.ST7789( + height=135 if display_type == "rect" else 240, + rotation=0 if display_type == "rect" else 90, + port=0, + cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT + dc=9, + backlight=19, # 18 for back BG slot, 19 for front BG slot. + spi_speed_hz=80 * 1000 * 1000, + offset_left=0 if display_type == "square" else 40, + offset_top=53 if display_type == "rect" else 0 + ) + +elif display_type == "dhmini": + disp = ST7789.ST7789( + height=240, + width=320, + rotation=180, + port=0, + cs=1, + dc=9, + backlight=13, + spi_speed_hz=60 * 1000 * 1000, + offset_left=0, + offset_top=0 + ) + +else: + print ("Invalid display type!") # Initialize display. disp.begin()