Skip to content

Commit 0038785

Browse files
add animated test
1 parent c2872fe commit 0038785

File tree

2 files changed

+95
-37
lines changed

2 files changed

+95
-37
lines changed

examples/waveviz_animated_test.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 JG for Cedar Grove Maker Studios
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import board
6+
import displayio
7+
import adafruit_ili9341
8+
from cedargrove_wavebuilder import WaveBuilder, WaveShape
9+
from cedargrove_waveviz import WaveViz
10+
11+
# Define wave table parameters
12+
WAVE_TABLE_LENGTH = 512 # The wave table length in samples
13+
SAMPLE_MAXIMUM = 32700 # The maximum value of a sample
14+
15+
# Instantiate a built-in display
16+
# display = board.DISPLAY
17+
18+
# Instantiate the FeatherS2 with 2.4-inch TFT FeatherWing display
19+
displayio.release_displays() # Release display resources
20+
display_bus = displayio.FourWire(
21+
board.SPI(), command=board.D6, chip_select=board.D5, reset=None
22+
)
23+
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
24+
display.rotation = 0
25+
26+
splash = displayio.Group()
27+
display.root_group = splash
28+
29+
# Define the Harmonica wave shape, overtone ratio, and amplitude
30+
tone = [
31+
(WaveShape.Sine, 1.00, 0.10),
32+
(WaveShape.Sine, 2.00, 0.48),
33+
(WaveShape.Sine, 3.00, 0.28),
34+
(WaveShape.Sine, 4.00, 0.02),
35+
(WaveShape.Sine, 5.00, 0.12),
36+
]
37+
38+
# Create the wave table (wave.wave_table)
39+
wave = WaveBuilder(
40+
oscillators=tone,
41+
table_length=WAVE_TABLE_LENGTH,
42+
sample_max=SAMPLE_MAXIMUM,
43+
lambda_factor=1.0,
44+
loop_smoothing=True,
45+
debug=False,
46+
)
47+
48+
# Display a small version on the bottom layer
49+
small = WaveViz(wave.wave_table, x=0, y=0, width=40, height=40, back_color=0x0000A0)
50+
splash.append(small)
51+
52+
# Display a full-sized version on the top layer
53+
large = WaveViz(wave.wave_table, x=20, y=20, width=280, height=200, back_color=None)
54+
splash.append(large)
55+
56+
while True:
57+
for x in range(large.width):
58+
small.x = x - (small.width // 2) + large.x
59+
small.y = (
60+
(large.height // 2)
61+
- int(
62+
(
63+
wave.wave_table[int(x * WAVE_TABLE_LENGTH / large.width)]
64+
/ large.max_result
65+
)
66+
* large.height
67+
// 2
68+
)
69+
- (small.width // 2)
70+
+ large.y
71+
)
72+
time.sleep(0.010)
73+
for x in range(large.width - 1, -1, -1):
74+
small.x = x - (small.width // 2) + large.x
75+
small.y = (
76+
(large.height // 2)
77+
- int(
78+
(
79+
wave.wave_table[int(x * WAVE_TABLE_LENGTH / large.width)]
80+
/ large.max_result
81+
)
82+
* large.height
83+
// 2
84+
)
85+
- (small.width // 2)
86+
+ large.y
87+
)
88+
time.sleep(0.010)

examples/waveviz_simpletest.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2024 JG for Cedar Grove Maker Studios
22
# SPDX-License-Identifier: MIT
33

4-
import time
54
import board
65
import displayio
76
import adafruit_ili9341
@@ -46,43 +45,14 @@
4645
)
4746

4847
# Display a small version on the bottom layer
49-
small = WaveViz(wave.wave_table, x=0, y=0, width=40, height=40, back_color=0x0000A0)
50-
splash.append(small)
48+
splash.append(
49+
WaveViz(wave.wave_table, x=20, y=80, width=25, height=25, back_color=0x0000A0)
50+
)
5151

5252
# Display a full-sized version on the top layer
53-
large = WaveViz(wave.wave_table, x=20, y=20, width=280, height=200, back_color=None)
54-
splash.append(large)
53+
splash.append(
54+
WaveViz(wave.wave_table, x=0, y=0, width=300, height=240, back_color=None)
55+
)
5556

5657
while True:
57-
for x in range(large.width):
58-
small.x = x - (small.width // 2) + large.x
59-
small.y = (
60-
(large.height // 2)
61-
- int(
62-
(
63-
wave.wave_table[int(x * WAVE_TABLE_LENGTH / large.width)]
64-
/ large.max_result
65-
)
66-
* large.height
67-
// 2
68-
)
69-
- (small.width // 2)
70-
+ large.y
71-
)
72-
time.sleep(0.010)
73-
for x in range(large.width - 1, -1, -1):
74-
small.x = x - (small.width // 2) + large.x
75-
small.y = (
76-
(large.height // 2)
77-
- int(
78-
(
79-
wave.wave_table[int(x * WAVE_TABLE_LENGTH / large.width)]
80-
/ large.max_result
81-
)
82-
* large.height
83-
// 2
84-
)
85-
- (small.width // 2)
86-
+ large.y
87-
)
88-
time.sleep(0.010)
58+
pass

0 commit comments

Comments
 (0)