|
34 | 34 | from adafruit_display_shapes.line import Line |
35 | 35 | from adafruit_display_shapes.rect import Rect |
36 | 36 |
|
37 | | -import gc |
38 | | - |
39 | | -# from sparkline import sparkline # use this if sparkline.py is used to define the sparkline Class |
40 | | - |
41 | | - |
42 | | -# Setup the LCD display |
43 | | - |
44 | | -displayio.release_displays() |
45 | | - |
46 | | - |
47 | | -# setup the SPI bus |
48 | | -spi = board.SPI() |
49 | | -tft_cs = board.D9 # arbitrary, pin not used |
50 | | -tft_dc = board.D10 |
51 | | -tft_backlight = board.D12 |
52 | | -tft_reset = board.D11 |
53 | | - |
54 | | -while not spi.try_lock(): |
55 | | - spi.configure(baudrate=32000000) |
56 | | - pass |
57 | | -spi.unlock() |
58 | | - |
59 | | -display_bus = displayio.FourWire( |
60 | | - spi, |
61 | | - command=tft_dc, |
62 | | - chip_select=tft_cs, |
63 | | - reset=tft_reset, |
64 | | - baudrate=32000000, |
65 | | - polarity=1, |
66 | | - phase=1, |
67 | | -) |
| 37 | +if "DISPLAY" not in dir(board): |
| 38 | + # Setup the LCD display with driver |
| 39 | + # You may need to change this to match the display driver for the chipset |
| 40 | + # used on your display |
| 41 | + from adafruit_ili9341 import ILI9341 |
| 42 | + |
| 43 | + displayio.release_displays() |
| 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 | + ) |
68 | 66 |
|
69 | | -print("spi.frequency: {}".format(spi.frequency)) |
| 67 | + print("spi.frequency: {}".format(spi.frequency)) |
70 | 68 |
|
71 | | -# Number of pixels in the display |
72 | | -DISPLAY_WIDTH = 320 |
73 | | -DISPLAY_HEIGHT = 240 |
| 69 | + # Number of pixels in the display |
| 70 | + DISPLAY_WIDTH = 320 |
| 71 | + DISPLAY_HEIGHT = 240 |
74 | 72 |
|
75 | | -# create the display |
76 | | -display = ILI9341( |
77 | | - display_bus, |
78 | | - width=DISPLAY_WIDTH, |
79 | | - height=DISPLAY_HEIGHT, |
80 | | - rotation=180, |
81 | | - auto_refresh=True, |
82 | | - native_frames_per_second=90, |
83 | | -) |
| 73 | + # create the display |
| 74 | + display = ILI9341( |
| 75 | + display_bus, |
| 76 | + width=DISPLAY_WIDTH, |
| 77 | + height=DISPLAY_HEIGHT, |
| 78 | + rotation=180, # The rotation can be adjusted to match your configuration. |
| 79 | + auto_refresh=True, |
| 80 | + native_frames_per_second=90, |
| 81 | + ) |
84 | 82 |
|
85 | | -# reset the display to show nothing. |
86 | | -display.show(None) |
| 83 | + # reset the display to show nothing. |
| 84 | + display.show(None) |
| 85 | +else: |
| 86 | + # built-in display |
| 87 | + display = board.DISPLAY |
87 | 88 |
|
88 | 89 | ########################################## |
89 | 90 | # Create background bitmaps and sparklines |
90 | 91 | ########################################## |
91 | 92 |
|
92 | 93 | # Baseline size of the sparkline chart, in pixels. |
93 | | -chartWidth = 270 |
94 | | -chartHeight = 180 |
| 94 | +chartWidth = display.width - 50 |
| 95 | +chartHeight = display.height - 50 |
95 | 96 |
|
96 | 97 | font = terminalio.FONT |
97 | 98 |
|
|
168 | 169 | ) |
169 | 170 | ) |
170 | 171 |
|
171 | | - |
172 | | -# Display myGroup that contains all the bitmap TileGrids and sparklines |
| 172 | +# Set the display to show myGroup that contains the sparkline and other graphics |
173 | 173 | display.show(myGroup) |
174 | 174 |
|
175 | | - |
176 | 175 | # Start the main loop |
177 | 176 | while True: |
178 | 177 |
|
| 178 | + # Turn off auto_refresh to prevent partial updates of the screen during updates |
| 179 | + # of the sparkline drawing |
| 180 | + display.auto_refresh = False |
| 181 | + |
179 | 182 | # add_value: add a new value to a sparkline |
180 | 183 | # Note: The y-range for mySparkline1 is set to 0 to 10, so all these random |
181 | 184 | # values (between 0 and 10) will fit within the visible range of this sparkline |
182 | 185 | mySparkline1.add_value(random.uniform(0, 10)) |
183 | 186 |
|
184 | | - # Turn off auto_refresh to prevent partial updates of the screen during updates |
185 | | - # of the sparkline drawing |
186 | | - display.auto_refresh = False |
187 | | - # Update all the sparklines |
188 | | - mySparkline1.update() |
189 | 187 | # Turn on auto_refresh for the display |
190 | 188 | display.auto_refresh = True |
191 | 189 |
|
192 | 190 | # The display seems to be less jittery if a small sleep time is provided |
193 | 191 | # You can adjust this to see if it has any effect |
194 | 192 | time.sleep(0.01) |
195 | | - |
196 | | - # Uncomment the next line to print the amount of available memory |
197 | | - # print('memory free: {}'.format(gc.mem_free())) |
0 commit comments