Skip to content

Commit 24539d4

Browse files
committed
add dreidel code
1 parent 0aae1a4 commit 24539d4

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

TFT_Gizmo_Dreidel/dreidel.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import time
2+
import random
3+
import board
4+
import displayio
5+
import adafruit_imageload
6+
from adafruit_circuitplayground.bluefruit import cpb
7+
from adafruit_gizmo import tft_gizmo
8+
9+
# define melody to play while spinning (freq, duration)
10+
melody = (
11+
# oh drei del drei del
12+
(330, 8), (392, 8), (330, 8), (392, 8), (330, 8),
13+
# drei del I made it
14+
(392, 8), (330, 16), (330, 8), (392, 8), (392, 8),
15+
# out of clay
16+
(349, 8), (330, 8), (294, 16), (0, 8),
17+
# oh drei del drei del
18+
(294, 8), (349, 8), (294, 8), (349, 8), (294, 8),
19+
# drei del then drei del
20+
(349, 8), (294, 16), (294, 8), (392, 8), (349, 8),
21+
# I shall play
22+
(330, 8), (294, 8), (262, 16),
23+
)
24+
melody_tempo = 0.02
25+
26+
# setup TFT Gizmo and main display group (splash)
27+
display = tft_gizmo.TFT_Gizmo()
28+
splash = displayio.Group()
29+
display.show(splash)
30+
31+
# load dreidel background image
32+
dreidel_bmp, dreidel_pal = adafruit_imageload.load("/dreidel_background.bmp",
33+
bitmap=displayio.Bitmap,
34+
palette=displayio.Palette)
35+
dreidel_tg = displayio.TileGrid(dreidel_bmp, pixel_shader=dreidel_pal)
36+
splash.append(dreidel_tg)
37+
38+
# load dreidel symbols (sprite sheet)
39+
symbols_bmp, symbols_pal = adafruit_imageload.load("/dreidel_sheet.bmp",
40+
bitmap=displayio.Bitmap,
41+
palette=displayio.Palette)
42+
for index, color in enumerate(symbols_pal):
43+
if color == 0xFFFF01:
44+
symbols_pal.make_transparent(index)
45+
symbols_tg = displayio.TileGrid(symbols_bmp, pixel_shader=symbols_pal,
46+
width = 1,
47+
height = 1,
48+
tile_width = 60,
49+
tile_height = 60)
50+
symbols_group = displayio.Group(scale=2, x=60, y=70)
51+
symbols_group.append(symbols_tg)
52+
splash.append(symbols_group)
53+
54+
# dreidel time!
55+
tile = 0
56+
while True:
57+
# wait for shake
58+
while not cpb.shake():
59+
pass
60+
# play melody while "spinning" the symbols
61+
for note, duration in melody:
62+
symbols_tg[0] = tile % 4
63+
tile += 1
64+
cpb.play_tone(note, duration * melody_tempo)
65+
# land on a random symbol
66+
symbols_tg[0] = random.randint(0, 3)
67+
# prevent immediate re-shake
68+
time.sleep(2)
57.4 KB
Binary file not shown.

TFT_Gizmo_Dreidel/dreidel_sheet.bmp

7.17 KB
Binary file not shown.

0 commit comments

Comments
 (0)