-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicroSpotListener.py
More file actions
55 lines (45 loc) · 1.44 KB
/
microSpotListener.py
File metadata and controls
55 lines (45 loc) · 1.44 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
#microSPOT | BBC microBit Spotify Controller by M.Argyle 11/26/18
import serial
import os
import time
from subprocess import call
playbackStatus = 0
shuffleStatus = 0
os.system("spotify stop")
# Open serial port to listen. You may need to edit tty addßress.
# Enter ls /tty.usb* in terminal after plugging button board in to
# find correct address
serialPort = serial.Serial("/dev/cu.usbmodem1412", 115200, timeout=0.5)
print "microSPOT is listening"
#listen for button, button sends single string over serial to trigger
while True:
command = serialPort.read()
#play/pause loop
if command == "p":
if playbackStatus == 0:
os.system("spotify play")
playbackStatus = 1
else:
os.system("spotify stop")
playbackStatus = 0
#next song loop
if command == ">":
os.system("spotify next")
#shuffle on off loop††å
if command == "s":
if shuffleStatus == 0:
os.system("spotify toggle shuffle")
os.system("spotify next")
shuffleStatus = 1
else:
os.system("spotify toggle shuffle")
shuffleStatus = 0
#volume down
if command == "-":
os.system("spotify vol down")
#volume up
if command == "+":
os.system("spotify vol up")
#super special song, edit to your liking
if command == "!":
os.system("spotify play walking on sunshine")