-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository
/
Copy pathspotifyarduino.ino
More file actions
More file actions
Latest commit
450 lines (393 loc) · 10.9 KB
/
spotifyarduino.ino
File metadata and controls
450 lines (393 loc) · 10.9 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#include ArduinoJson.h>gt;
#include Adafruit_GFX.h>gt;
#include Adafruit_ST7735.h>gt;
#include SPI.h>gt;
#include Arduino.h>gt;
#include WiFi.h>gt;
#include SpotifyEsp32.h>gt;
boolean oneTime = true;
boolean secondLine = false;
boolean secondLineTrack = false;
int progressCheck = 0;
boolean playing;
boolean getTop = true;
boolean topPlayed = false;
String lastArtist;
String lastTrackname;
// CHANGE ALL THESE TO CONTAIN YOUR INFO!
char* SSID = "";
const char* PASSWORD = "";
const char* CLIENT_ID = "";
const char* CLIENT_SECRET = "";
const char* REFRESH_TOKEN = "";
// CHANGE BUTTON PINS HERE
#define leftButton 10
#define middleButton 8
#define rightButton 6
// CHANGE SCREEN PINS HERE
#define TFT_CS 5
#define TFT_RST 4
#define TFT_DC 3
#define TFT_SCLK 2
#define TFT_MOSI 1
const unsigned char spotifyLogo[] PROGMEM = {
0x00, 0x07, 0x80, 0x00,
0x00, 0x3f, 0xf0, 0x00,
0x00, 0xff, 0xfc, 0x00,
0x03, 0xff, 0xff, 0x00,
0x07, 0xff, 0xff, 0x80,
0x0f, 0xff, 0xff, 0xc0,
0x1f, 0xff, 0xff, 0xe0,
0x1f, 0xff, 0xff, 0xe0,
0x3f, 0x80, 0x7f, 0xf0,
0x38, 0x00, 0x03, 0xf0,
0x78, 0x00, 0x00, 0xf8,
0x78, 0xff, 0xc0, 0x78,
0x7f, 0xff, 0xf8, 0x38,
0xff, 0x80, 0x7f, 0x7c,
0xfc, 0x00, 0x0f, 0xfc,
0xfc, 0x00, 0x03, 0xfc,
0xff, 0xff, 0xe0, 0xfc,
0x7f, 0xff, 0xf8, 0xf8,
0x7e, 0x00, 0x3f, 0xf8,
0x7e, 0x00, 0x0f, 0xf8,
0x3f, 0xff, 0x83, 0xf0,
0x3f, 0xff, 0xf3, 0xf0,
0x1f, 0xff, 0xff, 0xe0,
0x1f, 0xff, 0xff, 0xe0,
0x0f, 0xff, 0xff, 0xc0,
0x07, 0xff, 0xff, 0x80,
0x03, 0xff, 0xff, 0x00,
0x00, 0xff, 0xfc, 0x00,
0x00, 0x3f, 0xf0, 0x00,
0x00, 0x07, 0x80, 0x00
};
const unsigned char playIcon[] PROGMEM = {
0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0xf0, 0x00,
0x03, 0xfc, 0x00,
0x07, 0xff, 0x00,
0x0f, 0xff, 0x00,
0x1f, 0xff, 0x80,
0x1e, 0x67, 0x80,
0x3e, 0x67, 0xc0,
0x3e, 0x67, 0xc0,
0x3e, 0x67, 0xc0,
0x3e, 0x67, 0xc0,
0x1e, 0x67, 0x80,
0x1f, 0xff, 0x80,
0x0f, 0xff, 0x00,
0x07, 0xfe, 0x00,
0x03, 0xfc, 0x00,
0x00, 0xf0, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
const unsigned char pauseIcon[] PROGMEM = {
0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0xf0, 0x00,
0x03, 0xfc, 0x00,
0x07, 0xff, 0x00,
0x0f, 0xff, 0x00,
0x1f, 0xff, 0x80,
0x1f, 0x3f, 0x80,
0x3e, 0x0f, 0xc0,
0x3e, 0x07, 0xc0,
0x3e, 0x07, 0xc0,
0x3e, 0x0f, 0xc0,
0x1f, 0x3f, 0x80,
0x1f, 0xff, 0x80,
0x0f, 0xff, 0x00,
0x07, 0xfe, 0x00,
0x03, 0xfc, 0x00,
0x00, 0xf0, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
const unsigned char prev[] PROGMEM = {
0x00, 0xf0, 0x00,
tft.setCursor(40, 27);
tft.write(restOfTrack.substring(thirdLine.length(), restOfTrack.length()).c_str());
}
}
tft.fillRect(0,124,180,4,ST77XX_BLACK);
checkInput();
}
if (progressCheck == 2) {
checkProgress();
progressCheck = 0;
} else {
progressCheck++;
}
}
void connect_to_wifi() {
WiFi.begin(SSID, PASSWORD);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.printf("\nConnected to WiFi\n");
}
void checkProgress() {
StaticJsonDocument200> filter;er;
filter["item"]["duration_ms"] = true;
filter["progress_ms"] = true;
response r = sp.current_playback_state(filter);
int progressMs = r.reply["progress_ms"];
int durationMs = r.reply["item"]["duration_ms"];
double percentage = (double)progressMs/(double)durationMs;
Serial.println(progressMs);
Serial.println(durationMs);
Serial.println(percentage);
tft.setCursor(0,124);
tft.fillRect(0,124,(int)(160*percentage),4, ST77XX_GREEN);
}
void checkInput() {
if (digitalRead(middleButton) == LOW) {
Serial.println("pause/unpause!");
if (playing) {
tft.fillRect(70, 100, 20, 20, ST77XX_BLACK);
tft.drawBitmap(70, 100, pauseIcon, 20, 20, ST77XX_WHITE);
sp.pause_playback();
playing = false;
} else {
tft.fillRect(70, 100, 20, 20, ST77XX_BLACK);
tft.drawBitmap(70, 100, playIcon, 20, 20, ST77XX_WHITE);
sp.start_resume_playback();
playing = true;
}
}
if (digitalRead(rightButton) == LOW) {
tft.drawBitmap(115, 100, next, 20, 20, ST77XX_GREEN);
sp.skip();
tft.drawBitmap(115, 100, next, 20, 20, ST77XX_WHITE);
}
if (digitalRead(leftButton) == LOW) {
tft.drawBitmap(25, 100, prev, 20, 20, ST77XX_GREEN);
sp.previous();
tft.drawBitmap(25, 100, prev, 20, 20, ST77XX_WHITE);
}
}