File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ import time
2
+ import board
3
+ import digitalio
4
+
5
+ worm_ratio = 40 / 1
6
+ belt_ratio = 100 / 60
7
+ gear_ratio = worm_ratio * belt_ratio
8
+
9
+ steps = 200 # Steps per revolution
10
+ microsteps = 64 # Microstepping resolution
11
+ total_steps = steps * microsteps # Total microsteps per revolution
12
+
13
+ wait = 1 / ((gear_ratio * total_steps ) / 86400 )
14
+
15
+ step = digitalio .DigitalInOut (board .D6 )
16
+ direct = digitalio .DigitalInOut (board .D5 )
17
+
18
+ step .direction = digitalio .Direction .OUTPUT
19
+ direct .direction = digitalio .Direction .OUTPUT
20
+
21
+ direct .value = True
22
+
23
+ while True :
24
+ step .value = True
25
+ time .sleep (0.001 )
26
+ step .value = False
27
+ time .sleep (wait - 0.001 )
Original file line number Diff line number Diff line change
1
+ import time
2
+ import board
3
+ import digitalio
4
+ import usb_midi
5
+ import adafruit_midi
6
+ from adafruit_midi .note_on import NoteOn
7
+
8
+ # pins for the solenoid output signals
9
+ noid_pins = [board .D5 , board .D6 , board .D9 , board .D10 ]
10
+
11
+ # array for the solenoids
12
+ noids = []
13
+
14
+ # setup for the solenoid pins to be outputs
15
+ for pin in noid_pins :
16
+ noid = digitalio .DigitalInOut (pin )
17
+ noid .direction = digitalio .Direction .OUTPUT
18
+ noids .append (noid )
19
+
20
+ # MIDI note array
21
+ notes = [60 , 61 , 62 , 63 ]
22
+
23
+ # MIDI in setup
24
+ midi = adafruit_midi .MIDI (midi_in = usb_midi .ports [0 ], in_channel = 0 )
25
+
26
+ # delay for solenoids
27
+ speed = 0.03
28
+ retract = 0
29
+
30
+ while True :
31
+
32
+ # msg holds MIDI messages
33
+ msg = midi .receive ()
34
+
35
+ for i in range (4 ):
36
+ # states for solenoid on/off
37
+ noid_output = noids [i ]
38
+
39
+ # states for MIDI note recieved
40
+ notes_played = notes [i ]
41
+
42
+ # if NoteOn msg comes in and the MIDI note # matches with predefined notes:
43
+ if isinstance (msg , NoteOn ) and msg .note is notes_played :
44
+ print (time .monotonic (), msg .note )
45
+
46
+ # solenoid is triggered
47
+ noid_output .value = True
48
+ # quick delay
49
+ retract = time .monotonic ()
50
+
51
+ # retracts solenoid using time.monotonic() to avoid delays between notes activating
52
+ if (retract + speed ) < time .monotonic ():
53
+ noid_output .value = False
You can’t perform that action at this time.
0 commit comments