Skip to content

Commit aed3311

Browse files
committed
2 parents 5eb47df + 7d9b072 commit aed3311

78 files changed

Lines changed: 18464 additions & 355 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CircuitPython_Essentials/CircuitPython_Logger_Boot.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
# For Gemma M0, Trinket M0, Metro M0/M4 Express, ItsyBitsy M0/M4 Express
66
switch = digitalio.DigitalInOut(board.D2)
7-
# switch = digitalio.DigitalInOut(board.D5) # For Feather M0/M4 Express
8-
# switch = digitalio.DigitalInOut(board.D7) # For Circuit Playground Express
7+
8+
# For Feather M0/M4 Express
9+
# switch = digitalio.DigitalInOut(board.D5)
10+
11+
# For Circuit Playground Express, Circuit Playground Bluefruit
12+
# switch = digitalio.DigitalInOut(board.D7)
13+
914
switch.direction = digitalio.Direction.INPUT
1015
switch.pull = digitalio.Pull.UP
1116

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
"""
2+
Continuously scroll randomly generated After Dark style toasters.
3+
Designed for an ItsyBitsy M4 Express and a 1.3" 240x240 TFT
4+
5+
Adafruit invests time and resources providing this open source code.
6+
Please support Adafruit and open source hardware by purchasing
7+
products from Adafruit!
8+
9+
Written by Dave Astels for Adafruit Industries
10+
Copyright (c) 2019 Adafruit Industries
11+
Licensed under the MIT license.
12+
13+
All text above must be included in any redistribution.
14+
15+
Requires CircuitPython 5.0 or later.
16+
"""
17+
18+
import time
19+
from random import seed, randint
20+
import board
21+
import displayio
22+
from adafruit_st7789 import ST7789
23+
import adafruit_imageload
24+
25+
26+
# Sprite cell values
27+
EMPTY = 0
28+
CELL_1 = EMPTY + 1
29+
CELL_2 = CELL_1 + 1
30+
CELL_3 = CELL_2 + 1
31+
CELL_4 = CELL_3 + 1
32+
TOAST = CELL_4 + 1
33+
34+
NUMBER_OF_SPRITES = TOAST + 1
35+
36+
# Animation support
37+
38+
FIRST_CELL = CELL_1
39+
LAST_CELL = CELL_4
40+
41+
NUMBER_OF_CELLS = (LAST_CELL - FIRST_CELL) + 1
42+
43+
# A boolean array corresponding to the sprites, True if it's part of the animation sequence.
44+
ANIMATED = [_sprite >= FIRST_CELL and _sprite <= LAST_CELL for _sprite in range(NUMBER_OF_SPRITES)]
45+
46+
47+
# The chance (out of 10) that a new toaster, or toast will enter
48+
CHANCE_OF_NEW_TOASTER = 5
49+
CHANCE_OF_NEW_TOAST = 2
50+
51+
# How many sprites to styart with
52+
INITIAL_NUMBER_OF_SPRITES= 5
53+
54+
# Global variables
55+
display = None
56+
tilegrid = None
57+
58+
seed(int(time.monotonic()))
59+
60+
def make_display():
61+
"""Set up the display support.
62+
Return the Display object.
63+
"""
64+
spi = board.SPI()
65+
while not spi.try_lock():
66+
pass
67+
spi.configure(baudrate=24000000) # Configure SPI for 24MHz
68+
spi.unlock()
69+
tft_cs = board.D10
70+
tft_dc = board.D7
71+
72+
displayio.release_displays()
73+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
74+
75+
return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)
76+
77+
def make_tilegrid():
78+
"""Construct and return the tilegrid."""
79+
group = displayio.Group(max_size=10)
80+
81+
sprite_sheet, palette = adafruit_imageload.load("/spritesheet.bmp",
82+
bitmap=displayio.Bitmap,
83+
palette=displayio.Palette)
84+
grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
85+
width=9, height=9,
86+
tile_height=32, tile_width=32,
87+
x=0, y=-32,
88+
default_tile=EMPTY)
89+
group.append(grid)
90+
display.show(group)
91+
return grid
92+
93+
def random_cell():
94+
return randint(FIRST_CELL, LAST_CELL)
95+
96+
def evaluate_position(row, col):
97+
"""Return whether how long of aa toaster is placable at the given location.
98+
:param row: the tile row (0-9)
99+
:param col: the tile column (0-9)
100+
"""
101+
return tilegrid[col, row] == EMPTY
102+
103+
def seed_toasters(number_of_toasters):
104+
"""Create the initial toasters so it doesn't start empty"""
105+
for _ in range(number_of_toasters):
106+
while True:
107+
row = randint(0, 8)
108+
col = randint(0, 8)
109+
if evaluate_position(row, col):
110+
break
111+
tilegrid[col, row] = random_cell()
112+
113+
def next_sprite(sprite):
114+
if ANIMATED[sprite]:
115+
return (((sprite - FIRST_CELL) + 1) % NUMBER_OF_CELLS) + FIRST_CELL
116+
return sprite
117+
118+
def advance_animation():
119+
"""Cycle through animation cells each time."""
120+
for tile_number in range(81):
121+
tilegrid[tile_number] = next_sprite(tilegrid[tile_number])
122+
123+
def slide_tiles():
124+
"""Move the tilegrid one pixel to the bottom-left."""
125+
tilegrid.x -= 1
126+
tilegrid.y += 1
127+
128+
def shift_tiles():
129+
"""Move tiles one spot to the left, and reset the tilegrid's position"""
130+
for row in range(8, 0, -1):
131+
for col in range(8):
132+
tilegrid[col, row] = tilegrid[col + 1, row - 1]
133+
tilegrid[8, row] = EMPTY
134+
for col in range(9):
135+
tilegrid[col, 0] = EMPTY
136+
tilegrid.x = 0
137+
tilegrid.y = -32
138+
139+
def get_entry_row():
140+
while True:
141+
row = randint(0, 8)
142+
if tilegrid[8, row] == EMPTY and tilegrid[7, row] == EMPTY:
143+
return row
144+
145+
def get_entry_column():
146+
while True:
147+
col = randint(0, 8)
148+
if tilegrid[col, 0] == EMPTY and tilegrid[col, 1] == EMPTY:
149+
return col
150+
151+
def add_toaster_or_toast():
152+
"""Maybe add a new toaster or toast on the right and/or top at a randon open location"""
153+
if randint(1, 10) <= CHANCE_OF_NEW_TOAST:
154+
tile = TOAST
155+
elif randint(1, 10) <= CHANCE_OF_NEW_TOASTER:
156+
tile = random_cell()
157+
else:
158+
tile = EMPTY
159+
tilegrid[8, get_entry_row()] = tile
160+
161+
if randint(1, 10) <= CHANCE_OF_NEW_TOAST:
162+
tile = TOAST
163+
elif randint(1, 8) <= CHANCE_OF_NEW_TOASTER:
164+
tile = random_cell()
165+
else:
166+
tile = EMPTY
167+
tilegrid[get_entry_column(), 0] = tile
168+
169+
display = make_display()
170+
tilegrid = make_tilegrid()
171+
seed_toasters(INITIAL_NUMBER_OF_SPRITES)
172+
display.refresh()
173+
174+
while True:
175+
for _ in range(32):
176+
display.refresh(target_frames_per_second=80)
177+
advance_animation()
178+
slide_tiles()
179+
shift_tiles()
180+
add_toaster_or_toast()
181+
display.refresh(target_frames_per_second=120)
9.12 KB
Binary file not shown.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
Continuously scroll randomly generated Mario style clouds.
3+
Designed fr an ItsyBitsy M4 Express and a 1.3" 240x240 TFT
4+
5+
Adafruit invests time and resources providing this open source code.
6+
Please support Adafruit and open source hardware by purchasing
7+
products from Adafruit!
8+
9+
Written by Dave Astels for Adafruit Industries
10+
Copyright (c) 2019 Adafruit Industries
11+
Licensed under the MIT license.
12+
13+
All text above must be included in any redistribution.
14+
"""
15+
16+
import time
17+
from random import seed, randint
18+
import board
19+
import displayio
20+
from adafruit_st7789 import ST7789
21+
import adafruit_imageload
22+
23+
# Sprite cell values
24+
EMPTY = 0
25+
LEFT = 1
26+
MIDDLE = 2
27+
RIGHT = 3
28+
29+
# These constants determine what happens when tiles are shifted.
30+
# if randint(1, 10) > the value, the thing happens
31+
32+
# The chance a new cloud will enter
33+
CHANCE_OF_NEW_CLOUD = 4
34+
35+
# The chance an existing cloud gets extended
36+
CHANCE_OF_EXTENDING_A_CLOUD = 5
37+
38+
# Global variables
39+
display = None
40+
tilegrid = None
41+
42+
seed(int(time.monotonic()))
43+
44+
def make_display():
45+
"""Set up the display support.
46+
Return the Display object.
47+
"""
48+
spi = board.SPI()
49+
while not spi.try_lock():
50+
pass
51+
spi.configure(baudrate=24000000) # Configure SPI for 24MHz
52+
spi.unlock()
53+
tft_cs = board.D10
54+
tft_dc = board.D7
55+
56+
displayio.release_displays()
57+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
58+
59+
return ST7789(display_bus, width=240, height=240, rowstart=80)
60+
61+
def make_tilegrid():
62+
"""Construct and return the tilegrid."""
63+
group = displayio.Group(max_size=10)
64+
65+
sprite_sheet, palette = adafruit_imageload.load("/tilesheet.bmp",
66+
bitmap=displayio.Bitmap,
67+
palette=displayio.Palette)
68+
grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
69+
width=16, height=10,
70+
tile_height=24, tile_width=16,
71+
default_tile=EMPTY)
72+
group.append(grid)
73+
display.show(group)
74+
return grid
75+
76+
def evaluate_position(row, col):
77+
"""Return how long of a cloud is placable at the given location.
78+
:param row: the tile row (0-9)
79+
:param col: the tile column (0-14)
80+
"""
81+
if tilegrid[col, row] != EMPTY or tilegrid[col + 1, row] != EMPTY:
82+
return 0
83+
end_col = col + 1
84+
while end_col < 16 and tilegrid[end_col, row] == EMPTY:
85+
end_col += 1
86+
return min([4, end_col - col])
87+
88+
def seed_clouds(number_of_clouds):
89+
"""Create the initial clouds so it doesn't start empty"""
90+
for _ in range(number_of_clouds):
91+
while True:
92+
row = randint(0, 9)
93+
col = randint(0,14)
94+
cloud_length = evaluate_position(row, col)
95+
if cloud_length > 0:
96+
break
97+
l = randint(1, cloud_length)
98+
tilegrid[col, row] = LEFT
99+
for _ in range(l - 2):
100+
col += 1
101+
tilegrid[col, row] = MIDDLE
102+
tilegrid[col + 1, row] = RIGHT
103+
104+
def slide_tiles():
105+
"""Move the tilegrid to the left, one pixel at a time, a full time width"""
106+
for _ in range(16):
107+
tilegrid.x -= 1
108+
display.refresh_soon()
109+
display.wait_for_frame()
110+
111+
def shift_tiles():
112+
"""Move tiles one spot to the left, and reset the tilegrid's position"""
113+
for row in range(10):
114+
for col in range(15):
115+
tilegrid[col, row] = tilegrid[col + 1, row]
116+
tilegrid[15, row] = EMPTY
117+
tilegrid.x = 0
118+
119+
def extend_clouds():
120+
"""Extend any clouds on the right edge, either finishing them with a right
121+
end or continuing them with a middle piece
122+
"""
123+
for row in range(10):
124+
if tilegrid[14, row] == LEFT or tilegrid[14, row] == MIDDLE:
125+
if randint(1, 10) > CHANCE_OF_EXTENDING_A_CLOUD:
126+
tilegrid[15, row] = MIDDLE
127+
else:
128+
tilegrid[15, row] = RIGHT
129+
130+
def add_cloud():
131+
"""Maybe add a new cloud on the right at a randon open row"""
132+
if randint(1, 10) > CHANCE_OF_NEW_CLOUD:
133+
while True:
134+
row = randint(0, 9)
135+
if tilegrid[14, row] == EMPTY and tilegrid[15, row] == EMPTY:
136+
break
137+
tilegrid[15, row] = LEFT
138+
139+
display = make_display()
140+
tilegrid = make_tilegrid()
141+
seed_clouds(5)
142+
143+
while True:
144+
slide_tiles()
145+
shift_tiles()
146+
extend_clouds()
147+
add_cloud()
1.57 KB
Binary file not shown.

Dashblock_API/Coin.wav

41.7 KB
Binary file not shown.

Dashblock_API/adabot_cover.bmp

150 KB
Binary file not shown.

0 commit comments

Comments
 (0)