-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (25 loc) · 771 Bytes
/
main.py
File metadata and controls
32 lines (25 loc) · 771 Bytes
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
from time import sleep
import sys
from mfrc522 import SimpleMFRC522
import spotify
from album_mapping import NFC_TO_ALBUM
import RPi.GPIO as GPIO
reader = SimpleMFRC522()
last_uri = ""
try:
while True:
print("Hold a tag near the reader")
id, text = reader.read()
print("ID: %s\nText: %s" % (id,text))
last_3_chars = id % 1000
spotify_uri = NFC_TO_ALBUM.get(last_3_chars)
if not spotify_uri:
print("NFC not in dict {}".format(last_3_chars))
elif spotify_uri != last_uri: # Don't play it twice
last_uri = spotify_uri
print("Playing {}".format(spotify_uri))
spotify.play(spotify_uri)
sleep(5)
except KeyboardInterrupt:
GPIO.cleanup()
raise