Skip to content

Commit f38603c

Browse files
committed
Code and sound effects for tombstone project
Adding code and sound effects for the tombstone project.
1 parent 3d9b38b commit f38603c

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

Tombstone_Matrix_Prop-Maker/code.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import os
2+
import random
3+
import board
4+
import audiocore
5+
import audiobusio
6+
import audiomixer
7+
import pwmio
8+
from digitalio import DigitalInOut, Direction
9+
import neopixel
10+
from adafruit_motor import servo
11+
from adafruit_ticks import ticks_ms, ticks_add, ticks_diff
12+
from adafruit_led_animation.animation.pulse import Pulse
13+
from adafruit_led_animation.color import RED, BLACK, GREEN
14+
import adafruit_display_text.label
15+
import displayio
16+
import framebufferio
17+
import rgbmatrix
18+
import terminalio
19+
import adafruit_vl53l4cd
20+
21+
distance_trigger = 90 # cm
22+
text="Here lies Fred"
23+
text_color = 0xff0000
24+
# how often to check for a new trigger from ToF
25+
pause_time = 30 # seconds
26+
# speed for scrolling the text on the matrix
27+
scroll_time = 0.1 # seconds
28+
29+
displayio.release_displays()
30+
31+
# enable external power pin
32+
# provides power to the external components
33+
external_power = DigitalInOut(board.EXTERNAL_POWER)
34+
external_power.direction = Direction.OUTPUT
35+
external_power.value = True
36+
37+
i2c = board.I2C()
38+
vl53 = adafruit_vl53l4cd.VL53L4CD(i2c)
39+
40+
vl53.inter_measurement = 0
41+
vl53.timing_budget = 200
42+
43+
matrix = rgbmatrix.RGBMatrix(
44+
width=64, height=32, bit_depth=4,
45+
rgb_pins=[board.D6, board.D5, board.D9, board.D11, board.D10, board.D12],
46+
addr_pins=[board.D25, board.D24, board.A3, board.A2],
47+
clock_pin=board.D13, latch_pin=board.D0, output_enable_pin=board.D1)
48+
49+
display = framebufferio.FramebufferDisplay(matrix, auto_refresh=True)
50+
51+
line1 = adafruit_display_text.label.Label(
52+
terminalio.FONT,
53+
color=text_color,
54+
text=text)
55+
line1.x = 1
56+
line1.y = 14
57+
58+
def scroll(line):
59+
line.x = line.x - 1
60+
line_width = line.bounding_box[2]
61+
if line.x < -line_width:
62+
line.x = display.width
63+
64+
g = displayio.Group()
65+
g.append(line1)
66+
67+
display.show(g)
68+
69+
wavs = []
70+
for filename in os.listdir('/tomb_sounds'):
71+
if filename.lower().endswith('.wav') and not filename.startswith('.'):
72+
wavs.append("/tomb_sounds/"+filename)
73+
74+
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
75+
mixer = audiomixer.Mixer(voice_count=1, sample_rate=22050, channel_count=1,
76+
bits_per_sample=16, samples_signed=True, buffer_size=32768)
77+
78+
mixer.voice[0].level = 1
79+
audio.play(mixer)
80+
wav_length = len(wavs) - 1
81+
82+
def open_audio(num):
83+
n = wavs[num]
84+
f = open(n, "rb")
85+
w = audiocore.WaveFile(f)
86+
return w
87+
88+
PIXEL_PIN = board.EXTERNAL_NEOPIXELS
89+
BRIGHTNESS = 0.3
90+
NUM_PIXELS = 2
91+
92+
PIXELS = neopixel.NeoPixel(PIXEL_PIN, NUM_PIXELS, auto_write=True)
93+
pulse = Pulse(PIXELS, speed=0.05, color=RED, period=3)
94+
COLORS = [RED, GREEN, BLACK]
95+
96+
SERVO_PIN = board.EXTERNAL_SERVO
97+
PWM = pwmio.PWMOut(SERVO_PIN, duty_cycle=2 ** 15, frequency=50)
98+
SERVO = servo.Servo(PWM)
99+
SERVO.angle = 0
100+
101+
clock = ticks_ms()
102+
the_time = 5000
103+
x = 0
104+
scroll_clock = ticks_ms()
105+
scroll_time = int(scroll_time * 1000)
106+
pause_clock = ticks_ms()
107+
pause_time = pause_time * 1000
108+
pause = False
109+
110+
vl53.start_ranging()
111+
112+
while True:
113+
114+
vl53.clear_interrupt()
115+
116+
if vl53.distance < distance_trigger:
117+
if not pause:
118+
print("Distance: {} cm".format(vl53.distance))
119+
SERVO.angle = 90
120+
wave = open_audio(random.randint(0, wav_length))
121+
mixer.voice[0].play(wave)
122+
while mixer.playing:
123+
pulse.color = COLORS[x]
124+
pulse.animate()
125+
if ticks_diff(ticks_ms(), scroll_clock) >= scroll_time:
126+
scroll(line1)
127+
display.refresh(minimum_frames_per_second=0)
128+
scroll_clock = ticks_add(scroll_clock, scroll_time)
129+
x = (x + 1) % 2
130+
pause = True
131+
print("paused")
132+
pause_clock = ticks_add(pause_clock, pause_time)
133+
else:
134+
if ticks_diff(ticks_ms(), pause_clock) >= pause_time:
135+
print("back to sensing")
136+
pause = False
137+
print("still paused")
138+
if ticks_diff(ticks_ms(), scroll_clock) >= scroll_time:
139+
print("Distance: {} cm".format(vl53.distance))
140+
scroll(line1)
141+
display.refresh(minimum_frames_per_second=0)
142+
scroll_clock = ticks_add(scroll_clock, scroll_time)
143+
SERVO.angle = 0
144+
pulse.color = COLORS[2]
145+
pulse.animate()
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)