|
29 | 29 | import random |
30 | 30 | import time |
31 | 31 | from adafruit_display_shapes.sparkline import Sparkline |
32 | | -from adafruit_ili9341 import ILI9341 |
| 32 | + |
33 | 33 | from adafruit_display_text import label |
34 | 34 |
|
35 | | -import gc |
36 | 35 |
|
37 | 36 | # from sparkline import sparkline # use this if sparkline.py is used to define the sparkline Class |
38 | 37 |
|
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 |
85 | 87 |
|
86 | 88 | ########################################## |
87 | 89 | # Create background bitmaps and sparklines |
88 | 90 | ########################################## |
89 | 91 |
|
90 | 92 | # Baseline size of the sparkline chart, in pixels. |
91 | | -chartWidth = DISPLAY_WIDTH |
92 | | -chartHeight = DISPLAY_HEIGHT |
| 93 | +chartWidth = display.width |
| 94 | +chartHeight = display.height |
93 | 95 |
|
94 | 96 |
|
95 | 97 | # mySparkline1 uses a vertical y range between 0 to 10 and will contain a maximum of 40 items |
|
0 commit comments