Skip to content

Commit 04d5333

Browse files
authored
Merge pull request #18 from helgibbons/master
Update examples
2 parents eb38e0a + f49307b commit 04d5333

File tree

4 files changed

+125
-45
lines changed

4 files changed

+125
-45
lines changed

examples/gif.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* square - 240x240 1.3" Square LCD
2323
* round - 240x240 1.3" Round LCD (applies an offset)
2424
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
25+
* dhmini - 320x240 2.0" Display HAT Mini
2526
""".format(path=sys.argv[0]))
2627
sys.exit(1)
2728

@@ -32,18 +33,37 @@
3233
except IndexError:
3334
display_type = "square"
3435

35-
# Create TFT LCD display class.
36-
disp = ST7789.ST7789(
37-
height=135 if display_type == "rect" else 240,
38-
rotation=0 if display_type == "rect" else 90,
39-
port=0,
40-
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
41-
dc=9,
42-
backlight=19, # 18 for back BG slot, 19 for front BG slot.
43-
spi_speed_hz=80 * 1000 * 1000,
44-
offset_left=0 if display_type == "square" else 40,
45-
offset_top=53 if display_type == "rect" else 0
46-
)
36+
# Create ST7789 LCD display class.
37+
38+
if display_type in ("square", "rect", "round"):
39+
disp = ST7789.ST7789(
40+
height=135 if display_type == "rect" else 240,
41+
rotation=0 if display_type == "rect" else 90,
42+
port=0,
43+
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
44+
dc=9,
45+
backlight=19, # 18 for back BG slot, 19 for front BG slot.
46+
spi_speed_hz=80 * 1000 * 1000,
47+
offset_left=0 if display_type == "square" else 40,
48+
offset_top=53 if display_type == "rect" else 0
49+
)
50+
51+
elif display_type == "dhmini":
52+
disp = ST7789.ST7789(
53+
height=240,
54+
width=320,
55+
rotation=180,
56+
port=0,
57+
cs=1,
58+
dc=9,
59+
backlight=13,
60+
spi_speed_hz=60 * 1000 * 1000,
61+
offset_left=0,
62+
offset_top=0
63+
)
64+
65+
else:
66+
print ("Invalid display type!")
4767

4868
# Initialize display.
4969
disp.begin()

examples/image.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* square - 240x240 1.3" Square LCD
2020
* round - 240x240 1.3" Round LCD (applies an offset)
2121
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
22+
* dhmini - 320x240 2.0" Display HAT Mini
2223
""".format(sys.argv[0]))
2324
sys.exit(1)
2425

@@ -30,17 +31,36 @@
3031
display_type = "square"
3132

3233
# Create ST7789 LCD display class.
33-
disp = ST7789.ST7789(
34-
height=135 if display_type == "rect" else 240,
35-
rotation=0 if display_type == "rect" else 90,
36-
port=0,
37-
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
38-
dc=9,
39-
backlight=19, # 18 for back BG slot, 19 for front BG slot.
40-
spi_speed_hz=80 * 1000 * 1000,
41-
offset_left=0 if display_type == "square" else 40,
42-
offset_top=53 if display_type == "rect" else 0
43-
)
34+
35+
if display_type in ("square", "rect", "round"):
36+
disp = ST7789.ST7789(
37+
height=135 if display_type == "rect" else 240,
38+
rotation=0 if display_type == "rect" else 90,
39+
port=0,
40+
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
41+
dc=9,
42+
backlight=19, # 18 for back BG slot, 19 for front BG slot.
43+
spi_speed_hz=80 * 1000 * 1000,
44+
offset_left=0 if display_type == "square" else 40,
45+
offset_top=53 if display_type == "rect" else 0
46+
)
47+
48+
elif display_type == "dhmini":
49+
disp = ST7789.ST7789(
50+
height=240,
51+
width=320,
52+
rotation=180,
53+
port=0,
54+
cs=1,
55+
dc=9,
56+
backlight=13,
57+
spi_speed_hz=60 * 1000 * 1000,
58+
offset_left=0,
59+
offset_top=0
60+
)
61+
62+
else:
63+
print ("Invalid display type!")
4464

4565
WIDTH = disp.width
4666
HEIGHT = disp.height

examples/scrolling-text.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* square - 240x240 1.3" Square LCD
2525
* round - 240x240 1.3" Round LCD (applies an offset)
2626
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
27+
* dhmini - 320x240 2.0" Display HAT Mini
2728
""".format(sys.argv[0]))
2829

2930
try:
@@ -38,17 +39,36 @@
3839

3940

4041
# Create ST7789 LCD display class.
41-
disp = ST7789.ST7789(
42-
height=135 if display_type == "rect" else 240,
43-
rotation=0 if display_type == "rect" else 90,
44-
port=0,
45-
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
46-
dc=9,
47-
backlight=19, # 18 for back BG slot, 19 for front BG slot.
48-
spi_speed_hz=80 * 1000 * 1000,
49-
offset_left=0 if display_type == "square" else 40,
50-
offset_top=53 if display_type == "rect" else 0
51-
)
42+
43+
if display_type in ("square", "rect", "round"):
44+
disp = ST7789.ST7789(
45+
height=135 if display_type == "rect" else 240,
46+
rotation=0 if display_type == "rect" else 90,
47+
port=0,
48+
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
49+
dc=9,
50+
backlight=19, # 18 for back BG slot, 19 for front BG slot.
51+
spi_speed_hz=80 * 1000 * 1000,
52+
offset_left=0 if display_type == "square" else 40,
53+
offset_top=53 if display_type == "rect" else 0
54+
)
55+
56+
elif display_type == "dhmini":
57+
disp = ST7789.ST7789(
58+
height=240,
59+
width=320,
60+
rotation=180,
61+
port=0,
62+
cs=1,
63+
dc=9,
64+
backlight=13,
65+
spi_speed_hz=60 * 1000 * 1000,
66+
offset_left=0,
67+
offset_top=0
68+
)
69+
70+
else:
71+
print ("Invalid display type!")
5272

5373
# Initialize display.
5474
disp.begin()

examples/shapes.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* square - 240x240 1.3" Square LCD
2121
* round - 240x240 1.3" Round LCD (applies an offset)
2222
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
23+
* dhmini - 320x240 2.0" Display HAT Mini
2324
""".format(sys.argv[0]))
2425

2526
try:
@@ -28,17 +29,36 @@
2829
display_type = "square"
2930

3031
# Create ST7789 LCD display class.
31-
disp = ST7789.ST7789(
32-
height=135 if display_type == "rect" else 240,
33-
rotation=0 if display_type == "rect" else 90,
34-
port=0,
35-
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
36-
dc=9,
37-
backlight=19, # 18 for back BG slot, 19 for front BG slot.
38-
spi_speed_hz=80 * 1000 * 1000,
39-
offset_left=0 if display_type == "square" else 40,
40-
offset_top=53 if display_type == "rect" else 0
41-
)
32+
33+
if display_type in ("square", "rect", "round"):
34+
disp = ST7789.ST7789(
35+
height=135 if display_type == "rect" else 240,
36+
rotation=0 if display_type == "rect" else 90,
37+
port=0,
38+
cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
39+
dc=9,
40+
backlight=19, # 18 for back BG slot, 19 for front BG slot.
41+
spi_speed_hz=80 * 1000 * 1000,
42+
offset_left=0 if display_type == "square" else 40,
43+
offset_top=53 if display_type == "rect" else 0
44+
)
45+
46+
elif display_type == "dhmini":
47+
disp = ST7789.ST7789(
48+
height=240,
49+
width=320,
50+
rotation=180,
51+
port=0,
52+
cs=1,
53+
dc=9,
54+
backlight=13,
55+
spi_speed_hz=60 * 1000 * 1000,
56+
offset_left=0,
57+
offset_top=0
58+
)
59+
60+
else:
61+
print ("Invalid display type!")
4262

4363
# Initialize display.
4464
disp.begin()

0 commit comments

Comments
 (0)