Skip to content

Commit 5ec10a2

Browse files
committed
update hwtest for modern circuitpython
1 parent d523a15 commit 5ec10a2

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

circuitpython/hwtest/code.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import analogio, keypad
2424
import audiobusio, audiomixer, synthio
2525
import ulab.numpy as np
26-
import displayio, terminalio
26+
import i2cdisplaybus, displayio, terminalio
2727
import adafruit_displayio_ssd1306
2828
from adafruit_display_text import bitmap_label as label
2929
import touchio
@@ -34,7 +34,7 @@
3434
midi_notes = list(range(45,45+16))
3535
filter_freq = 4000
3636
filter_resonance = 1.2
37-
output_volume = 0.75 # turn down the volume a bit since this can get loud
37+
output_volume = 1.0
3838

3939
# pin definitions
4040
sw_pin = board.GP28
@@ -67,17 +67,17 @@
6767
for pin in touch_pins:
6868
print("touch pin:", pin)
6969
touchin = touchio.TouchIn(pin)
70-
touchin.threshold = int(touchin.threshold * 1.05)
70+
touchin.threshold = int(touchin.threshold * 1.1)
7171
touchins.append(touchin)
7272
touchs.append(Debouncer(touchin))
7373

74-
74+
print("starting up...")
7575
midi_in_usb = usb_midi.ports[0]
7676
midi_in_uart = busio.UART(rx=uart_rx_pin, tx=uart_tx_pin, baudrate=31250, timeout=0.001)
7777
i2c = busio.I2C(scl=i2c_scl_pin, sda=i2c_sda_pin, frequency=1_000_000)
7878

7979
dw,dh = 128, 64
80-
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
80+
display_bus = i2cdisplaybus.I2CDisplayBus(i2c, device_address=0x3c)
8181
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=dw, height=dh, rotation=180)
8282

8383
# set up the synth->audio system
@@ -98,7 +98,7 @@
9898

9999
# set up info to be displayed
100100
maingroup = displayio.Group()
101-
display.show(maingroup)
101+
display.root_group = maingroup
102102
text1 = label.Label(terminalio.FONT, text="pico_test_synth", x=0, y=10)
103103
text2 = label.Label(terminalio.FONT, text="@todbot", x=0, y=25)
104104
text3 = label.Label(terminalio.FONT, text="pico_test_synth!", x=0, y=50)
@@ -116,13 +116,14 @@ def check_touch():
116116
if touch.rose:
117117
print("touch press",i)
118118
f = synthio.midi_to_hz(midi_notes[i])
119-
filter = synth.low_pass_filter(filter_freq, filter_resonance)
120-
n = synthio.Note( frequency=f, waveform=wave_saw, filter=filter )
119+
filter = synthio.Biquad(synthio.FilterMode.LOW_PASS, filter_freq, filter_resonance)
120+
n = synthio.Note(frequency=f, waveform=wave_saw, filter=filter, amplitude=0.75)
121121
synth.press( n )
122122
touch_notes[i] = n
123123
if touch.fell:
124124
print("touch release", i)
125-
synth.release( touch_notes[i] )
125+
if touch_notes[i]:
126+
synth.release( touch_notes[i] )
126127

127128
async def debug_printer():
128129
t1_last = ""
@@ -153,8 +154,9 @@ async def input_handler():
153154

154155
for n in touch_notes: # real-time adjustment of filter
155156
if n:
156-
n.filter = synth.low_pass_filter(filter_freq, filter_resonance)
157-
157+
n.filter.frequency = filter_freq
158+
n.filter.Q = filter_resonance
159+
158160
check_touch()
159161

160162
if key := keys.events.get():
@@ -164,7 +166,7 @@ async def input_handler():
164166
if key.pressed:
165167
sw_pressed = True
166168
f = synthio.midi_to_hz(random.randint(32,60))
167-
note = synthio.Note(frequency=f, waveform=wave_saw) # , filter=filter)
169+
note = synthio.Note(frequency=f, waveform=wave_saw, amplitude=0.8)
168170
synth.press(note)
169171
await asyncio.sleep(0.001)
170172

circuitpython/hwtest/hwtest_captouch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import time
55
import board
66
import touchio
7+
import digitalio
8+
9+
pull_type = digitalio.Pull.UP
710

811
touch_pins = (
912
board.GP0, board.GP1, board.GP2, board.GP3, board.GP4, board.GP5,
@@ -13,7 +16,7 @@
1316
touchins = []
1417
for pin in touch_pins:
1518
print("touch pin:", pin) # print here let's us diagnose if a pin is bad
16-
touchin = touchio.TouchIn(pin)
19+
touchin = touchio.TouchIn(pin, pull=pull_type)
1720
touchin.threshold = int(touchin.threshold * 1.05)
1821
touchins.append(touchin)
1922

0 commit comments

Comments
 (0)