-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyForceSensorFullRange.py
More file actions
45 lines (30 loc) · 1.02 KB
/
myForceSensorFullRange.py
File metadata and controls
45 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
from ble_MIDI import *
from hub import *
import force_sensor
#Plug in Force Sensor to port C
#push force button to play a range of notes
#right button on hub disconnects
def done():
return button.pressed(button.RIGHT)
def play_note(note):
Piano.on(note, velocity['f'])
time.sleep(.1)
Piano.off(note)
time.sleep(.1)
def start():
try:
while not done():
fs = force_sensor.force(port.C)
print(fs)
note_range = 108 - 21 # Total number of notes in the range
note_value = int((fs / 100) * note_range) + 21 # Map the force sensor value to the note range
play_note(note_value)
except:
pass
print('disconnect')
midi.disconnect()
midi = MIDI_Player('emma')
midi.wait_for_connection()
Piano = MIDI_Instrument(midi, instruments['Acoustic Grand Piano'], channel=0)
start()