1+ # The MIT License (MIT)
2+ #
3+ # Copyright (c) 2020 Alethea Flowers for Winterbloom
4+ #
5+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6+ # of this software and associated documentation files (the "Software"), to deal
7+ # in the Software without restriction, including without limitation the rights
8+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+ # copies of the Software, and to permit persons to whom the Software is
10+ # furnished to do so, subject to the following conditions:
11+ #
12+ # The above copyright notice and this permission notice shall be included in
13+ # all copies or substantial portions of the Software.
14+ #
15+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+ # THE SOFTWARE.
22+
23+ import time
24+ import audioio
25+ import analogio
26+ import board
27+ import digitalio
28+
29+ button = digitalio .DigitalInOut (board .D2 )
30+ button .switch_to_input (pull = digitalio .Pull .UP )
31+ gate = digitalio .DigitalInOut (board .D0 )
32+ gate .switch_to_input ()
33+ pitch_cv = analogio .AnalogIn (board .A4 )
34+
35+ wave_file = open ("honk-sound.wav" , "rb" )
36+ wave = audioio .WaveFile (wave_file )
37+ audio = audioio .AudioOut (board .A0 )
38+
39+ last_button_value = False
40+ last_gate_value = False
41+ button_value = None
42+ gate_value = None
43+
44+ while True :
45+ button_value = not button .value
46+ gate_value = not gate .value
47+
48+ if (not last_button_value and button_value ) or (not last_gate_value and gate_value ):
49+ print (pitch_cv .value )
50+ wave .sample_rate = int (44100 * ((pitch_cv .value / 65355 ) + 0.5 ))
51+ audio .play (wave )
52+
53+ last_button_value = button_value
54+ last_gate_value = gate_value
0 commit comments