-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusicbot.py
50 lines (38 loc) · 1.26 KB
/
musicbot.py
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 libraries
import time
from adafruit_servokit import ServoKit
from midi import *
from songChoice import *
def __init__():
# funny
print("Initializing Microwave", end="")
time.sleep(0.2)
print(" . ", end="")
time.sleep(0.2)
print(" . ", end="")
time.sleep(0.2)
print(" . ", end="")
time.sleep(0.2)
print(end="\n")
__init__()
# set channels for the ServoKit
kit = ServoKit(channels=16)
# all servos can be rotated 180 degrees, the min and max, also known as the on and off states of the servos is written below :
off = 90
on = 80 # this is the distance the servo has to spin to be in the on position
midiR = MidiReader(get_song_request().dir)
# we have 13 "keys" we can press at once, so we will calculate the max and min notes, and subtract by the min to find my range, and thus know which notes need to be struck
print("Song Selected Has Range : ", midiR.range)
if (midiR.range) > 13:
print(
"SONG CANNOT BE PLAYED!!! \nSONG REQUIRES ",
{midiR.range},
" NOTES OF RANGE, AND WE HAVE 13!!!",
)
exit(1)
def play_song():
for msg in midiR.messages:
print(msg)
time.sleep(msg.len)
kit.servo[msg.note - midiR.min].angle = (off) + (msg.on * on) # this is cursed
play_song()