Skip to content

Commit 9784b7b

Browse files
authored
Merge pull request #1 from FoamyGuy/generalize_display_in_examples
update the simpletest to generalize the display setup
2 parents 46bceae + 2ba35db commit 9784b7b

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

examples/display_shapes_sparkline_simpletest.py

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,67 +29,69 @@
2929
import random
3030
import time
3131
from adafruit_display_shapes.sparkline import Sparkline
32-
from adafruit_ili9341 import ILI9341
32+
3333
from adafruit_display_text import label
3434

35-
import gc
3635

3736
# from sparkline import sparkline # use this if sparkline.py is used to define the sparkline Class
3837

39-
40-
# Setup the LCD display
41-
42-
displayio.release_displays()
43-
44-
45-
# setup the SPI bus
46-
spi = board.SPI()
47-
tft_cs = board.D9 # arbitrary, pin not used
48-
tft_dc = board.D10
49-
tft_backlight = board.D12
50-
tft_reset = board.D11
51-
52-
while not spi.try_lock():
53-
spi.configure(baudrate=32000000)
54-
pass
55-
spi.unlock()
56-
57-
display_bus = displayio.FourWire(
58-
spi,
59-
command=tft_dc,
60-
chip_select=tft_cs,
61-
reset=tft_reset,
62-
baudrate=32000000,
63-
polarity=1,
64-
phase=1,
65-
)
66-
67-
print("spi.frequency: {}".format(spi.frequency))
68-
69-
# Number of pixels in the display
70-
DISPLAY_WIDTH = 320
71-
DISPLAY_HEIGHT = 240
72-
73-
# create the display
74-
display = ILI9341(
75-
display_bus,
76-
width=DISPLAY_WIDTH,
77-
height=DISPLAY_HEIGHT,
78-
rotation=180,
79-
auto_refresh=True,
80-
native_frames_per_second=90,
81-
)
82-
83-
# reset the display to show nothing.
84-
display.show(None)
38+
if "DISPLAY" not in dir(board):
39+
# Setup the LCD display with driver
40+
from adafruit_ili9341 import ILI9341
41+
42+
displayio.release_displays()
43+
44+
# setup the SPI bus
45+
spi = board.SPI()
46+
tft_cs = board.D9 # arbitrary, pin not used
47+
tft_dc = board.D10
48+
tft_backlight = board.D12
49+
tft_reset = board.D11
50+
51+
while not spi.try_lock():
52+
spi.configure(baudrate=32000000)
53+
pass
54+
spi.unlock()
55+
56+
display_bus = displayio.FourWire(
57+
spi,
58+
command=tft_dc,
59+
chip_select=tft_cs,
60+
reset=tft_reset,
61+
baudrate=32000000,
62+
polarity=1,
63+
phase=1,
64+
)
65+
66+
print("spi.frequency: {}".format(spi.frequency))
67+
68+
# Number of pixels in the display
69+
DISPLAY_WIDTH = 320
70+
DISPLAY_HEIGHT = 240
71+
72+
# create the display
73+
display = ILI9341(
74+
display_bus,
75+
width=DISPLAY_WIDTH,
76+
height=DISPLAY_HEIGHT,
77+
rotation=180,
78+
auto_refresh=True,
79+
native_frames_per_second=90,
80+
)
81+
82+
# reset the display to show nothing.
83+
display.show(None)
84+
else:
85+
# built-in display
86+
display = board.DISPLAY
8587

8688
##########################################
8789
# Create background bitmaps and sparklines
8890
##########################################
8991

9092
# Baseline size of the sparkline chart, in pixels.
91-
chartWidth = DISPLAY_WIDTH
92-
chartHeight = DISPLAY_HEIGHT
93+
chartWidth = display.width
94+
chartHeight = display.height
9395

9496

9597
# mySparkline1 uses a vertical y range between 0 to 10 and will contain a maximum of 40 items

0 commit comments

Comments
 (0)