2
2
import board
3
3
import busio
4
4
import displayio
5
- from adafruit_st7789 import ST7789
5
+ from adafruit_gizmo import tft_gizmo
6
6
import adafruit_imageload
7
7
import adafruit_lis3dh
8
8
24
24
accelo_i2c = busio .I2C (board .ACCELEROMETER_SCL , board .ACCELEROMETER_SDA )
25
25
accelo = adafruit_lis3dh .LIS3DH_I2C (accelo_i2c , address = 0x19 )
26
26
27
- # Display setup
28
- WIDTH = 240
29
- HEIGHT = 240
30
- displayio .release_displays ()
31
-
32
- spi = busio .SPI (board .SCL , MOSI = board .SDA )
33
- tft_cs = board .RX
34
- tft_dc = board .TX
35
- tft_backlight = board .A3
36
-
37
- display_bus = displayio .FourWire (spi , command = tft_dc , chip_select = tft_cs )
38
-
39
- display = ST7789 (display_bus , width = WIDTH , height = HEIGHT , rowstart = 80 ,
40
- backlight_pin = tft_backlight , rotation = 180 )
27
+ # Create the TFT Gizmo display
28
+ display = tft_gizmo .TFT_Gizmo ()
41
29
42
30
# Load background image
43
31
try :
47
35
# Or just use solid color
48
36
except (OSError , TypeError ):
49
37
BACKGROUND = BACKGROUND if isinstance (BACKGROUND , int ) else 0x000000
50
- bg_bitmap = displayio .Bitmap (WIDTH , HEIGHT , 1 )
38
+ bg_bitmap = displayio .Bitmap (display . width , display . height , 1 )
51
39
bg_palette = displayio .Palette (1 )
52
40
bg_palette [0 ] = BACKGROUND
53
41
background = displayio .TileGrid (bg_bitmap , pixel_shader = bg_palette )
71
59
height = 1 ,
72
60
tile_width = FLAKE_WIDTH ,
73
61
tile_height = FLAKE_HEIGHT ,
74
- x = randrange (0 , WIDTH ),
62
+ x = randrange (0 , display . width ),
75
63
default_tile = randrange (0 , NUM_SPRITES )))
76
64
77
65
# Snowfield setup
78
- snow_depth = [HEIGHT ] * WIDTH
66
+ snow_depth = [display . height ] * display . width
79
67
snow_palette = displayio .Palette (2 )
80
68
snow_palette [0 ] = 0xADAF00 # transparent color
81
69
snow_palette [1 ] = SNOW_COLOR # snow color
82
70
snow_palette .make_transparent (0 )
83
- snow_bitmap = displayio .Bitmap (WIDTH , HEIGHT , len (snow_palette ))
71
+ snow_bitmap = displayio .Bitmap (display . width , display . height , len (snow_palette ))
84
72
snow = displayio .TileGrid (snow_bitmap , pixel_shader = snow_palette )
85
73
86
74
# Add everything to display
@@ -98,13 +86,13 @@ def clear_the_snow():
98
86
# set to a random sprite
99
87
flake [0 ] = randrange (0 , NUM_SPRITES )
100
88
# set to a random x location
101
- flake .x = randrange (0 , WIDTH )
89
+ flake .x = randrange (0 , display . width )
102
90
# set random y locations, off screen to start
103
- flake_pos = [- 1.0 * randrange (0 , HEIGHT ) for _ in range (NUM_FLAKES )]
91
+ flake_pos = [- 1.0 * randrange (0 , display . height ) for _ in range (NUM_FLAKES )]
104
92
# reset snow level
105
- snow_depth = [HEIGHT ] * WIDTH
93
+ snow_depth = [display . height ] * display . width
106
94
# and snow bitmap
107
- for i in range (WIDTH * HEIGHT ):
95
+ for i in range (display . width * display . height ):
108
96
snow_bitmap [i ] = 0
109
97
display .auto_refresh = True
110
98
@@ -117,11 +105,11 @@ def add_snow(index, amount, steepness=2):
117
105
# check depth to right
118
106
if snow_depth [x + 1 ] - snow_depth [x ] < steepness :
119
107
add = True
120
- elif x == WIDTH - 1 :
108
+ elif x == display . width - 1 :
121
109
# check depth to left
122
110
if snow_depth [x - 1 ] - snow_depth [x ] < steepness :
123
111
add = True
124
- elif 0 < x < WIDTH - 1 :
112
+ elif 0 < x < display . width - 1 :
125
113
# check depth to left AND right
126
114
if snow_depth [x - 1 ] - snow_depth [x ] < steepness and \
127
115
snow_depth [x + 1 ] - snow_depth [x ] < steepness :
@@ -138,7 +126,7 @@ def add_snow(index, amount, steepness=2):
138
126
while True :
139
127
clear_the_snow ()
140
128
# loop until globe is full of snow
141
- while snow_depth .count (0 ) < WIDTH :
129
+ while snow_depth .count (0 ) < display . width :
142
130
# check for shake
143
131
if accelo .shake (SHAKE_THRESHOLD , 5 , 0 ):
144
132
break
@@ -153,6 +141,6 @@ def add_snow(index, amount, steepness=2):
153
141
# reset flake to top
154
142
flake_pos [i ] = 0
155
143
# at a new x location
156
- flake .x = randrange (0 , WIDTH )
144
+ flake .x = randrange (0 , display . width )
157
145
flake .y = int (flake_pos [i ])
158
146
display .refresh ()
0 commit comments