Skip to content

Commit 55cf6fc

Browse files
committed
gravity falls prop
adding code, sound effects and font file for gravity falls prop learn guide
1 parent 15f0e83 commit 55cf6fc

File tree

12 files changed

+27674
-0
lines changed

12 files changed

+27674
-0
lines changed

Gravity_Falls_Memory_Gun/Arial-14.bdf

Lines changed: 27566 additions & 0 deletions
Large diffs are not rendered by default.

Gravity_Falls_Memory_Gun/code.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
import board
7+
import audiocore
8+
import audiobusio
9+
from digitalio import DigitalInOut, Direction
10+
import displayio
11+
from adafruit_bitmap_font import bitmap_font
12+
from adafruit_display_text import label
13+
import adafruit_displayio_ssd1306
14+
from adafruit_seesaw import seesaw, rotaryio
15+
import vectorio
16+
import keypad
17+
18+
#display setup
19+
displayio.release_displays()
20+
# enable external power pin
21+
# provides power to the external components
22+
external_power = DigitalInOut(board.EXTERNAL_POWER)
23+
external_power.direction = Direction.OUTPUT
24+
external_power.value = False
25+
26+
# rotary encoder
27+
i2c = board.STEMMA_I2C()
28+
seesaw = seesaw.Seesaw(i2c, addr=0x36)
29+
encoder = rotaryio.IncrementalEncoder(seesaw)
30+
last_position = 0
31+
32+
# oled
33+
oled_reset = board.D9
34+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D, reset=oled_reset)
35+
WIDTH = 128
36+
HEIGHT = 64
37+
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
38+
39+
# trigger button
40+
switch = keypad.Keys((board.EXTERNAL_BUTTON,), value_when_pressed=False, pull=True)
41+
42+
# audio!
43+
wavs = []
44+
wav_names = []
45+
for filename in os.listdir('/wavs'):
46+
if filename.lower().endswith('.wav') and not filename.startswith('.'):
47+
wavs.append("/wavs/"+filename)
48+
wav_names.append(filename.replace('.wav', ''))
49+
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
50+
num_wavs = len(wavs)
51+
wav_index = 0
52+
# function to open and play the audio files
53+
def open_audio(num):
54+
n = wavs[num]
55+
# pylint: disable = consider-using-with
56+
f = open(n, "rb")
57+
w = audiocore.WaveFile(f)
58+
return w
59+
wave = open_audio(wav_index)
60+
audio.play(wave)
61+
62+
# make the display context
63+
splash = displayio.Group()
64+
display.root_group = splash
65+
palette = displayio.Palette(1)
66+
palette[0] = 0xFFFFFF
67+
rect = vectorio.Rectangle(pixel_shader=palette, width=display.width, height=23, x=6, y=21)
68+
splash.append(rect)
69+
font = bitmap_font.load_font("/Arial-14.bdf")
70+
color = 0xFFFFFF
71+
text_0 = wav_names[(wav_index - 1) % num_wavs]
72+
text_area_top_left = label.Label(font, text=text_0, color=color)
73+
text_area_top_left.anchor_point = (0.0, 0.0)
74+
text_area_top_left.anchored_position = (6, 0)
75+
splash.append(text_area_top_left)
76+
77+
text_1 = wav_names[wav_index]
78+
text_area_middle_left = label.Label(font, text=text_1,color=0x000000)
79+
text_area_middle_left.anchor_point = (0.0, 0.5)
80+
text_area_middle_left.anchored_position = (6, display.height / 2)
81+
splash.append(text_area_middle_left)
82+
83+
text_2 = wav_names[(wav_index+1) % num_wavs]
84+
text_area_bottom_left = label.Label(font, text=text_2, color=color)
85+
text_area_bottom_left.anchor_point = (0.0, 1.0)
86+
text_area_bottom_left.anchored_position = (6, display.height)
87+
splash.append(text_area_bottom_left)
88+
89+
while True:
90+
91+
event = switch.events.get()
92+
position = encoder.position
93+
if position != last_position:
94+
if position > last_position:
95+
wav_index = (wav_index + 1) % num_wavs
96+
else:
97+
wav_index = (wav_index - 1) % num_wavs
98+
text_area_top_left.text = wav_names[(wav_index-1) % num_wavs]
99+
text_area_middle_left.text = wav_names[wav_index]
100+
text_area_bottom_left.text = wav_names[(wav_index+1) % num_wavs]
101+
last_position = position
102+
if event:
103+
if event.pressed:
104+
external_power.value = True
105+
wave = open_audio(wav_index)
106+
audio.play(wave)
107+
if event.released:
108+
external_power.value = False
21.6 KB
Binary file not shown.
21.6 KB
Binary file not shown.
21.6 KB
Binary file not shown.
18.9 KB
Binary file not shown.
41.3 KB
Binary file not shown.
35.9 KB
Binary file not shown.
21.6 KB
Binary file not shown.
16.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)