-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
38 lines (30 loc) · 903 Bytes
/
main.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
import time
import machine
from spotify_web_api import (
spotify_client,
SpotifyWebApiError,
)
def run(button):
print("Running")
spotify = spotify_client()
while True:
try:
if not button.value():
time.sleep(0.3)
if button.value():
print("Play: Seagulls! Stop it now!")
spotify.play(uris=["spotify:track:471sXvN5C5vfMSBdKrGpo7"])
else:
print("Pause")
spotify.pause()
while not button.value():
time.sleep(0.1)
time.sleep(0.05)
except SpotifyWebApiError as e:
print('Error: {}, Reason: {}'.format(e, e.reason))
def main():
print("\033c")
button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
run(button)
if __name__ == '__main__':
main()