-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyColorSensorSingleNote.py
More file actions
50 lines (34 loc) · 1.01 KB
/
myColorSensorSingleNote.py
File metadata and controls
50 lines (34 loc) · 1.01 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
46
47
48
49
50
import time
from ble_MIDI import *
from hub import *
import color_sensor
#Plug in Color Sensor to port E
#cover the light to activate a single note
#right button on hub disconnects
midi = MIDI_Player('emma')
midi.wait_for_connection()
Piano = MIDI_Instrument(midi, instruments['Acoustic Grand Piano'], channel=0)
def done():
return button.pressed(button.RIGHT)
def play_note(note):
Piano.on(note, velocity['f'])
time.sleep(0.1)
Piano.off(note)
time.sleep(0.1)
def read_light():
return color_sensor.reflection(port.E)
def activated():
return read_light() > 50
def start():
try:
while not done():
if activated():
print(color_sensor.reflection(port.E))
play_note(50)
else:
time.sleep(.1)
except:
pass
print('disconnect')
midi.disconnect()
start()