Skip to content

Commit e497da1

Browse files
committed
firmware: Add the ability to track pressed (triggered) and released for gate in and the button independently.
Note: This is a *breaking* change. `bhb.update()` must be called for every loop in `code.py`. To upgrade, just replace: ``` while True: ``` with ``` while bhb.update(): ``` in code.py. The examples have all been updated. Added two additional samples for separate press & release and separate button & gate. Closes #5
1 parent d6beb62 commit e497da1

File tree

11 files changed

+91
-50
lines changed

11 files changed

+91
-50
lines changed

examples/button_gate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This example shows how to play a different sample depending on if the
2+
# button is pressed or the gate in is triggered.
3+
4+
import winterbloom_bhb
5+
6+
bhb = winterbloom_bhb.BigHonkingButton()
7+
8+
snare = bhb.load_sample("samples/snare.wav")
9+
clap = bhb.load_sample("samples/clap.wav")
10+
11+
while bhb.update():
12+
if bhb.button.pressed:
13+
bhb.play(snare)
14+
elif bhb.gate_in.triggered:
15+
bhb.play(clap)

examples/cv_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
bhb.load_sample("samples/snare.wav"),
1616
]
1717

18-
while True:
18+
while bhb.update():
1919
if bhb.triggered:
2020
# This selects a sample from the list based on the pitch CV input.
2121
# The samples are evenly distributed across the CV range,

examples/cycle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
current_sample_no = 0
1818

19-
while True:
19+
while bhb.update():
2020
if bhb.triggered:
2121
bhb.gate_out = True
2222
bhb.play(samples[current_sample_no], pitch_cv=bhb.pitch_in)
@@ -25,4 +25,4 @@
2525
current_sample_no = 0
2626

2727
if bhb.released:
28-
bhb.gate_out = False
28+
bhb.gate_out = False

examples/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
bhb = winterbloom_bhb.BigHonkingButton()
99
sample = bhb.load_sample("samples/honk.wav")
1010

11-
while True:
11+
while bhb.update():
1212
if bhb.triggered:
1313
bhb.gate_out = True
1414
bhb.play(sample, pitch_cv=bhb.pitch_in)

examples/honk_burst.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""This example turns a Winterbloom Big Honking Button into a simple
2-
burst generator (that also happens to honk)
3-
"""
1+
# This example turns the Big Honking Button into a simple
2+
# burst generator (that also happens to honk)
3+
44
import time
55

66
import winterbloom_bhb
@@ -9,7 +9,7 @@
99
sample = bhb.load_sample("samples/honk.wav")
1010
burst_intervals = [0.05, 0.05, 0.05, 0.05, 0.1]
1111

12-
while True:
12+
while bhb.update():
1313
if bhb.triggered:
1414
for interval in burst_intervals:
1515
bhb.gate_out = True

examples/noise.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def generate_noise(volume=1.0):
1919

2020
for i in range(length):
2121
samples[i] = int(random.random() * volume)
22-
22+
2323
return samples
2424

2525
noise = generate_noise(0.8)
@@ -33,11 +33,11 @@ def generate_noise(volume=1.0):
3333
sample.sample_rate = frequency * len(noise)
3434

3535

36-
while True:
36+
while bhb.update():
3737
if bhb.triggered:
3838
bhb.gate_out = True
3939
bhb.play(sample, loop=True)
4040

4141
if bhb.released:
4242
bhb.gate_out = False
43-
bhb.stop()
43+
bhb.stop()

examples/press_release.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This example shows how to play a different sample when the button is
2+
# pressed and when the button is released.
3+
4+
import winterbloom_bhb
5+
6+
bhb = winterbloom_bhb.BigHonkingButton()
7+
8+
snare = bhb.load_sample("samples/snare.wav")
9+
reverse = bhb.load_sample("samples/reverse.wav")
10+
11+
while bhb.update():
12+
if bhb.triggered:
13+
bhb.gate_out = True
14+
bhb.play(snare)
15+
16+
if bhb.released:
17+
bhb.gate_out = False
18+
bhb.play(reverse)

examples/random.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
bhb.load_sample("samples/clap.wav"),
1313
]
1414

15-
while True:
15+
while bhb.update():
1616
if bhb.triggered:
1717
bhb.gate_out = True
1818
bhb.play(random.choice(samples), pitch_cv=bhb.pitch_in)
1919

2020
if bhb.released:
21-
bhb.gate_out = False
21+
bhb.gate_out = False

examples/sine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def generate_sine_wave(volume=1.0):
2222

2323
for i in range(length):
2424
samples[i] = int((1 + math.sin(math.pi * 2 * i / length)) * volume)
25-
25+
2626
return samples
2727

2828
sine_wave = generate_sine_wave(0.8)
@@ -35,11 +35,11 @@ def generate_sine_wave(volume=1.0):
3535
sample.sample_rate = frequency * len(sine_wave)
3636

3737

38-
while True:
38+
while bhb.update():
3939
if bhb.triggered:
4040
bhb.gate_out = True
4141
bhb.play(sample, loop=True)
4242

4343
if bhb.released:
4444
bhb.gate_out = False
45-
bhb.stop()
45+
bhb.stop()

examples/tap_tempo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
last_button_press = time.monotonic()
2626

2727

28-
while True:
28+
while bhb.update():
2929
# Get the current time and see if enough
3030
# time has passed to play the sample.
3131
now = time.monotonic()

0 commit comments

Comments
 (0)