-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (53 loc) · 1.58 KB
/
Copy pathmain.py
File metadata and controls
62 lines (53 loc) · 1.58 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
51
52
53
54
55
56
57
58
59
60
61
62
import tkinter as tk
from tkinter import Label
import serial
from time import sleep
from functools import partial
# retreive list of songs from playlist.txt
f = open("playlist.txt", 'r')
playlist = {}
for line in f:
k, v = line.strip().split('=')
playlist[int(k.strip())] = v.strip()
f.close()
# map each note to a character for Arduino communication
dict = {
"48": '0', # C
"50": '1', # D
"52": '2', # E
"53": '3', # F
"55": '4', # G
"57": '5', # A
"59": '6', # B
"60": '7', # C
"62": '8', # D
"64": '9', # E
"65": 'a', # F
"67": 'b', # G
"69": 'c', # A
"71": 'd', # B
"72": 'e' # C
}
# Enter your COM port in the below line
serial = serial.Serial('com5', 9600)
sleep(2)
#print (serial.readline(serial.inWaiting()))
root = tk.Tk()
def runSong(num):
label1.config(text = "Playing " + song)
sleep(1)
with open("txt/%d_GI15.txt" %num, "r") as f:
for line in f:
notes = line.rstrip("\n").rstrip().split()
# print(notes)
if notes: # beat contains notes
for i in range(len(notes)):
serial.write(dict[notes[i]].encode())
sleep(0.3) # tempo of song
# simple GUI using tkinter
label1 = Label(root, text = "Choose a song", fg="green")
label1.pack()
for num, song in playlist.items():
button = tk.Button(root, text = song, command = partial(runSong, num))
button.pack()
root.mainloop()