22import board
33import busio
44import displayio
5- from adafruit_st7789 import ST7789
5+ from adafruit_gizmo import tft_gizmo
66import adafruit_imageload
77import adafruit_lis3dh
88
2424accelo_i2c = busio .I2C (board .ACCELEROMETER_SCL , board .ACCELEROMETER_SDA )
2525accelo = adafruit_lis3dh .LIS3DH_I2C (accelo_i2c , address = 0x19 )
2626
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 ()
4129
4230# Load background image
4331try :
4735# Or just use solid color
4836except (OSError , TypeError ):
4937 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 )
5139 bg_palette = displayio .Palette (1 )
5240 bg_palette [0 ] = BACKGROUND
5341background = displayio .TileGrid (bg_bitmap , pixel_shader = bg_palette )
7159 height = 1 ,
7260 tile_width = FLAKE_WIDTH ,
7361 tile_height = FLAKE_HEIGHT ,
74- x = randrange (0 , WIDTH ),
62+ x = randrange (0 , display . width ),
7563 default_tile = randrange (0 , NUM_SPRITES )))
7664
7765# Snowfield setup
78- snow_depth = [HEIGHT ] * WIDTH
66+ snow_depth = [display . height ] * display . width
7967snow_palette = displayio .Palette (2 )
8068snow_palette [0 ] = 0xADAF00 # transparent color
8169snow_palette [1 ] = SNOW_COLOR # snow color
8270snow_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 ))
8472snow = displayio .TileGrid (snow_bitmap , pixel_shader = snow_palette )
8573
8674# Add everything to display
@@ -98,13 +86,13 @@ def clear_the_snow():
9886 # set to a random sprite
9987 flake [0 ] = randrange (0 , NUM_SPRITES )
10088 # set to a random x location
101- flake .x = randrange (0 , WIDTH )
89+ flake .x = randrange (0 , display . width )
10290 # 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 )]
10492 # reset snow level
105- snow_depth = [HEIGHT ] * WIDTH
93+ snow_depth = [display . height ] * display . width
10694 # and snow bitmap
107- for i in range (WIDTH * HEIGHT ):
95+ for i in range (display . width * display . height ):
10896 snow_bitmap [i ] = 0
10997 display .auto_refresh = True
11098
@@ -117,11 +105,11 @@ def add_snow(index, amount, steepness=2):
117105 # check depth to right
118106 if snow_depth [x + 1 ] - snow_depth [x ] < steepness :
119107 add = True
120- elif x == WIDTH - 1 :
108+ elif x == display . width - 1 :
121109 # check depth to left
122110 if snow_depth [x - 1 ] - snow_depth [x ] < steepness :
123111 add = True
124- elif 0 < x < WIDTH - 1 :
112+ elif 0 < x < display . width - 1 :
125113 # check depth to left AND right
126114 if snow_depth [x - 1 ] - snow_depth [x ] < steepness and \
127115 snow_depth [x + 1 ] - snow_depth [x ] < steepness :
@@ -138,7 +126,7 @@ def add_snow(index, amount, steepness=2):
138126while True :
139127 clear_the_snow ()
140128 # loop until globe is full of snow
141- while snow_depth .count (0 ) < WIDTH :
129+ while snow_depth .count (0 ) < display . width :
142130 # check for shake
143131 if accelo .shake (SHAKE_THRESHOLD , 5 , 0 ):
144132 break
@@ -153,6 +141,6 @@ def add_snow(index, amount, steepness=2):
153141 # reset flake to top
154142 flake_pos [i ] = 0
155143 # at a new x location
156- flake .x = randrange (0 , WIDTH )
144+ flake .x = randrange (0 , display . width )
157145 flake .y = int (flake_pos [i ])
158146 display .refresh ()
0 commit comments