Skip to content

Commit

Permalink
Nothing playing status
Browse files Browse the repository at this point in the history
  • Loading branch information
Duoslow committed May 16, 2023
1 parent b9670a6 commit 5104105
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
last_song = ''
while True:
current_track = spotify.current_user_playing_track()
artists = ', '.join([i['name'] for i in current_track['item']['artists']])
album = current_track['item']['album']['name']
track = current_track['item']['name']
now_playing = ' {} => {} '.format(artists, track)
if now_playing != last_song:
last_song = now_playing
# we need to close and reopen the serial connection to clear the lcd buffer
arduino.close() # Close serial connection to Arduino
arduino = serial.Serial(port=config['Arduino']['port'], baudrate=config['Arduino']['baudRate'], timeout=.1) # Reopen serial connection to Arduino
arduino.write(bytes(now_playing, 'utf-8'))
time.sleep(3)
# print('Currently playing: {}'.format(now_playing))
if current_track:
artists = ', '.join([i['name'] for i in current_track['item']['artists']])
album = current_track['item']['album']['name']
track = current_track['item']['name']
now_playing = ' {} => {} '.format(artists, track)
if now_playing != last_song:
last_song = now_playing
# we need to close and reopen the serial connection to clear the lcd buffer
arduino.close() # Close serial connection to Arduino
arduino = serial.Serial(port=config['Arduino']['port'], baudrate=config['Arduino']['baudRate'], timeout=.1) # Reopen serial connection to Arduino
arduino.write(bytes(now_playing, 'utf-8'))
print('Currently playing: {}'.format(now_playing))
time.sleep(3)
else:
arduino.write(bytes('Nothing playing', 'utf-8'))
print('Nothing playing')
time.sleep(3)

0 comments on commit 5104105

Please sign in to comment.