Skip to content

Commit ad3e9a3

Browse files
authored
Merge pull request #4 from makermelissa/master
Updated example to make it easier to change between different breakouts
2 parents 1227a78 + 986241b commit ad3e9a3

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

examples/displayio_ssd1306_simpletest.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,29 @@
1111

1212
displayio.release_displays()
1313

14-
spi = board.SPI()
15-
oled_cs = board.D5
16-
oled_dc = board.D6
17-
oled_reset = board.D9
14+
# Use for I2C
15+
i2c = board.I2C()
16+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
1817

19-
display_bus = displayio.FourWire(spi, command=oled_dc, chip_select=oled_cs,
20-
reset=oled_reset, baudrate=1000000)
21-
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
18+
# Use for SPI
19+
#spi = board.SPI()
20+
#oled_cs = board.D5
21+
#oled_dc = board.D6
22+
#oled_reset = board.D9
23+
#display_bus = displayio.FourWire(spi, command=oled_dc, chip_select=oled_cs,
24+
# reset=oled_reset, baudrate=1000000)
25+
26+
WIDTH = 128
27+
HEIGHT = 32 # Change to 64 if needed
28+
BORDER = 5
29+
30+
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
2231

2332
# Make the display context
2433
splash = displayio.Group(max_size=10)
2534
display.show(splash)
2635

27-
color_bitmap = displayio.Bitmap(128, 64, 1)
36+
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
2837
color_palette = displayio.Palette(1)
2938
color_palette[0] = 0xFFFFFF # White
3039

@@ -34,17 +43,17 @@
3443
splash.append(bg_sprite)
3544

3645
# Draw a smaller inner rectangle
37-
inner_bitmap = displayio.Bitmap(118, 54, 1)
46+
inner_bitmap = displayio.Bitmap(WIDTH-BORDER*2, HEIGHT-BORDER*2, 1)
3847
inner_palette = displayio.Palette(1)
3948
inner_palette[0] = 0x000000 # Black
4049
inner_sprite = displayio.TileGrid(inner_bitmap,
4150
pixel_shader=inner_palette,
42-
x=5, y=5)
51+
x=BORDER, y=BORDER)
4352
splash.append(inner_sprite)
4453

4554
# Draw a label
4655
text = "Hello World!"
47-
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=32)
56+
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=HEIGHT//2-1)
4857
splash.append(text_area)
4958

5059
while True:

0 commit comments

Comments
 (0)