-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesp32mediapublic.ino
More file actions
127 lines (103 loc) · 2.93 KB
/
esp32mediapublic.ino
File metadata and controls
127 lines (103 loc) · 2.93 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
119
120
121
122
123
124
125
126
127
#include <Arduino.h>
/**SPOTIFY libs**/
#include <WiFi.h>
//#define DBG_SERIAL
#define DISABLE_ALBUM
#define DISABLE_ARTIST
#define DISABLE_AUDIOBOOKS
#define DISABLE_CATEGORIES
#define DISABLE_CHAPTERS
#define DISABLE_EPISODES
#define DISABLE_GENRES
#define DISABLE_MARKETS
#define DISABLE_PLAYLISTS
#define DISABLE_SEARCH
#define DISABLE_SHOWS
#define DISABLE_TRACKS
#define DISABLE_WEB_SERVER
#include <SpotifyEsp32.h>
#include "settings.h"
/**END Spotify libs****/
/**OLED Libs**/
#include <Wire.h>
#include <U8g2lib.h>
/*END oled libs*/
/*touch buttons libs*/
#include "touchbutton.h"
/*END touch buttons libs*/
/**OLED vars**/
U8G2_SSD1306_128X64_NONAME_F_SW_I2C
u8g2(U8G2_R0,22,21,U8X8_PIN_NONE);/*22CLOCK/21 DATA*/
/**ENDS***/
Spotify sp(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN);
struct Button button1 = {BUTTON1, 0, 0,0,0};
struct Button button2 = {BUTTON2, 0, 0,0,0};
struct Button button3 = {BUTTON3, 0, 0,0,0};
struct Button button4 = {BUTTON4, 0, 0,0,0};
void setup() {
#ifdef DBG_SERIAL
Serial.begin(115200);
#endif
connect_to_wifi();
sp.begin();
while(!sp.is_auth()){
sp.handle_client();
}
#ifdef DBG_SERIAL
Serial.println("Authenticated");
#endif
sp.pause_playback();
u8g2.begin();
setup_buttons();
}
void drawLines(String song,String artis)
{
String temp = "volumen";
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_9x15_tr);
u8g2.drawStr(0,10,"Song playing");
u8g2.drawStr(0,21,(song.c_str()));
u8g2.drawStr(0,32,"Artist");
u8g2.drawStr(0,43,(artis.c_str()));
u8g2.drawStr(0,54,temp.c_str());
u8g2.sendBuffer();
}
void loop() {
static String lastArtist;
static String lastTrackname;
String currentArtist = sp.current_artist_names();
String currentTrackname = sp.current_track_name();
if (lastArtist != currentArtist && currentArtist != "Something went wrong" && !currentArtist.isEmpty()) {
lastArtist = currentArtist;
#ifdef DBG_SERIAL
Serial.println("Artist: " + lastArtist);
#endif
drawLines(currentTrackname,currentArtist);
}
if (lastTrackname != currentTrackname && currentTrackname != "Something went wrong" && currentTrackname != "null") {
lastTrackname = currentTrackname;
#ifdef DBG_SERIAL
Serial.println("Track: " + lastTrackname);
drawLines(currentTrackname,currentArtist);
#endif
}
checkPressed(&button1);
checkPressed(&button2);
checkPressed(&button3);
checkPressed(&button4);
}
void connect_to_wifi(){
WiFi.begin(SSID, PASSWORD);
#ifdef DBG_SERIAL
Serial.print("Connecting to WiFi...");
#endif
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
#ifdef DBG_SERIAL
Serial.print(".");
#endif
}
#ifdef DBG_SERIAL
Serial.printf("\nConnected to WiFi\n");
#endif
}