arduino-mixer/python/start.py
2020-05-20 23:06:03 +02:00

41 lines
1.2 KiB
Python

from pycaw.pycaw import AudioUtilities
from pprint import pprint
import serial
import serial.tools.list_ports
import time
def main():
print ("Starting Arduino Mixer...\n")
# Get audio sessions
sessions = AudioUtilities.GetAllSessions()
print (str(len(sessions)) + " audio sessions found:")
for session in sessions:
volume = session.SimpleAudioVolume
print (" " + str(session.Process))
# Init serial connection
ports = serial.tools.list_ports.comports()
if len(ports) == 0:
print("\nNo Serial ports Available")
exit()
else:
print ("\nSerial ports Available:")
for port, desc, hwid in sorted(ports):
print(" {}: {} [{}]".format(port, desc, hwid))
board = serial.Serial()
board.baudrate = 115200
board.port = input("\nSelect COM port: ")
board.open()
print ("Waiting for arduino...")
time.sleep(5)
board.write("<HELLO>".encode("utf-8"))
board.write("<COUNT,3>".encode("utf-8"))
board.write("<GETVOL,50>".encode("utf-8"))
board.write("<NAME,Test>".encode("utf-8"))
if __name__ == "__main__":
main()