@@ -61,36 +61,42 @@ Usage Example
61
61
.. code-block :: python
62
62
63
63
import board
64
+ import digitalio
64
65
import displayio
65
66
import terminalio
66
67
from adafruit_display_text import label
67
68
import adafruit_displayio_ssd1305
68
69
69
70
displayio.release_displays()
70
71
71
- oled_reset = board.D9
72
-
73
- # Use for I2C
74
- # i2c = board.I2C()
75
- # display_bus = displayio.I2CDisplay(i2c, device_address=0x3c, reset=oled_reset)
72
+ # Manually Toggle Reset
73
+ reset = digitalio.DigitalInOut(board.D9)
74
+ reset.switch_to_output(value = False )
75
+ reset.value = True
76
76
77
77
# Use for SPI
78
78
spi = board.SPI()
79
79
oled_cs = board.D5
80
80
oled_dc = board.D6
81
81
display_bus = displayio.FourWire(spi, command = oled_dc, chip_select = oled_cs,
82
- reset = oled_reset, baudrate = 1000000 )
82
+ baudrate = 1000000 )
83
+
84
+ # Use for I2C
85
+ # i2c = board.I2C()
86
+ # display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
87
+
83
88
WIDTH = 128
84
- HEIGHT = 64 # Change to 64 if needed
85
- BORDER = 5
89
+ HEIGHT = 64 # Change to 32 if needed
90
+ BORDER = 8
91
+ FONTSCALE = 1
86
92
87
93
display = adafruit_displayio_ssd1305.SSD1305(display_bus, width = WIDTH , height = HEIGHT )
88
94
89
95
# Make the display context
90
96
splash = displayio.Group(max_size = 10 )
91
97
display.show(splash)
92
98
93
- color_bitmap = displayio.Bitmap(WIDTH , HEIGHT , 1 )
99
+ color_bitmap = displayio.Bitmap(display.width, display.height , 1 )
94
100
color_palette = displayio.Palette(1 )
95
101
color_palette[0 ] = 0x FFFFFF # White
96
102
@@ -100,7 +106,7 @@ Usage Example
100
106
splash.append(bg_sprite)
101
107
102
108
# Draw a smaller inner rectangle
103
- inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2 , HEIGHT - BORDER * 2 , 1 )
109
+ inner_bitmap = displayio.Bitmap(display.width - BORDER * 2 , display.height - BORDER * 2 , 1 )
104
110
inner_palette = displayio.Palette(1 )
105
111
inner_palette[0 ] = 0x 000000 # Black
106
112
inner_sprite = displayio.TileGrid(inner_bitmap,
@@ -110,8 +116,12 @@ Usage Example
110
116
111
117
# Draw a label
112
118
text = " Hello World!"
113
- text_area = label.Label(terminalio.FONT , text = text, color = 0x FFFFFF , x = 28 , y = HEIGHT // 2 - 1 )
114
- splash.append(text_area)
119
+ text_area = label.Label(terminalio.FONT , text = text, color = 0x FFFFFF )
120
+ text_width = text_area.bounding_box[2 ] * FONTSCALE
121
+ text_group = displayio.Group(max_size = 10 , scale = FONTSCALE , x = display.width // 2 - text_width // 2 ,
122
+ y = display.height // 2 )
123
+ text_group.append(text_area) # Subgroup for text scaling
124
+ splash.append(text_group)
115
125
116
126
while True :
117
127
pass
0 commit comments