Skip to content

Commit a2b21d6

Browse files
authored
Merge pull request #7 from makermelissa/master
Spruce up examples
2 parents a28c424 + a7c3b22 commit a2b21d6

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

adafruit_ssd1327.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __init__(self, bus, **kwargs):
7979
if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
8080
height = kwargs["width"]
8181
init_sequence[18] = height - 1 # patch mux ratio
82-
print(height)
8382
super().__init__(
8483
bus,
8584
init_sequence,

examples/ssd1327_gamma.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import time
22
import board
3-
import busio
43
import displayio
54
import adafruit_ssd1327
65

76
displayio.release_displays()
87

9-
# This pinout works on a Metro and may need to be altered for other boards.
10-
spi = busio.SPI(board.SCL, board.SDA)
11-
tft_cs = board.D6
12-
tft_dc = board.D9
13-
tft_reset = board.D5
8+
# Use for I2C
9+
i2c = board.I2C()
10+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D)
11+
12+
# Use for SPI
13+
# spi = board.SPI()
14+
# oled_cs = board.D5
15+
# oled_dc = board.D6
16+
# display_bus = displayio.FourWire(
17+
# spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
18+
# )
19+
1420

15-
display_bus = displayio.FourWire(
16-
spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset, baudrate=1000000
17-
)
1821
time.sleep(1)
1922
display = adafruit_ssd1327.SSD1327(display_bus, width=128, height=128)
2023

examples/ssd1327_simpletest.py

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,68 @@
1-
import time
21
import board
3-
import busio
42
import displayio
3+
import terminalio
4+
from adafruit_display_text import label
55
import adafruit_ssd1327
66

77
displayio.release_displays()
88

9-
# This pinout works on a Metro and may need to be altered for other boards.
10-
spi = busio.SPI(board.SCL, board.SDA)
11-
tft_cs = board.D6
12-
tft_dc = board.D9
13-
tft_reset = board.D5
9+
# Use for I2C
10+
i2c = board.I2C()
11+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D)
1412

15-
display_bus = displayio.FourWire(
16-
spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset, baudrate=1000000
13+
# Use for SPI
14+
# spi = board.SPI()
15+
# oled_cs = board.D5
16+
# oled_dc = board.D6
17+
# display_bus = displayio.FourWire(
18+
# spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
19+
# )
20+
21+
WIDTH = 128
22+
HEIGHT = 128
23+
BORDER = 8
24+
FONTSCALE = 1
25+
26+
display = adafruit_ssd1327.SSD1327(display_bus, width=WIDTH, height=HEIGHT)
27+
28+
# Make the display context
29+
splash = displayio.Group(max_size=10)
30+
display.show(splash)
31+
32+
# Draw a background rectangle, but not the full display size
33+
color_bitmap = displayio.Bitmap(
34+
display.width - BORDER * 2, display.height - BORDER * 2, 1
35+
)
36+
color_palette = displayio.Palette(1)
37+
color_palette[0] = 0xFFFFFF # White
38+
bg_sprite = displayio.TileGrid(
39+
color_bitmap, pixel_shader=color_palette, x=BORDER, y=BORDER
1740
)
18-
time.sleep(1)
19-
display = adafruit_ssd1327.SSD1327(display_bus, width=128, height=128)
41+
splash.append(bg_sprite)
42+
43+
# Draw a smaller inner rectangle
44+
inner_bitmap = displayio.Bitmap(
45+
display.width - BORDER * 4, display.height - BORDER * 4, 1
46+
)
47+
inner_palette = displayio.Palette(1)
48+
inner_palette[0] = 0x888888 # Gray
49+
inner_sprite = displayio.TileGrid(
50+
inner_bitmap, pixel_shader=inner_palette, x=BORDER * 2, y=BORDER * 2
51+
)
52+
splash.append(inner_sprite)
53+
54+
# Draw a label
55+
text = "Hello World!"
56+
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF)
57+
text_width = text_area.bounding_box[2] * FONTSCALE
58+
text_group = displayio.Group(
59+
max_size=10,
60+
scale=FONTSCALE,
61+
x=display.width // 2 - text_width // 2,
62+
y=display.height // 2,
63+
)
64+
text_group.append(text_area) # Subgroup for text scaling
65+
splash.append(text_group)
66+
67+
while True:
68+
pass

0 commit comments

Comments
 (0)