-
Notifications
You must be signed in to change notification settings - Fork 2
/
bluetooth_recevier.ino
75 lines (68 loc) · 1.92 KB
/
bluetooth_recevier.ino
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
#include <SD.h>
#include <EEPROM.h>
#include <mp3.h>
#include <mp3conf.h>
#include <Song.h>
#include <JsonHandler.h>
char val; // variable to receive data from the Uart port
int ledpin = 11; // LED connected to pin 2 (on-board LED)
Song song;
JsonHandler handler;
void setup()
{
song.setup(&handler);
handler.setup();
song.sendPlayerState();
handler.respond();
pinMode(ledpin, OUTPUT); // pin 13 (on-board LED) as OUTPUT
}
void loop() {
if( handler.inputAvailable() ) { // if data is available to read
char command[120];
char data[10];
handler.readCommand(command, data);
handler.addKeyValuePair("command", command, true);
if (strcmp(command, "CONNECTED") == 0){
song.sendPlayerState();
}
else if (strcmp(command, "LED")==0){
int state = atoi(data);
digitalWrite(ledpin, state);
//state == HIGH ? Uart.print("LIGHT ON") : Uart.print("LIGHT OFF");
}
else if (strcmp(command, "PLAY")==0){
song.play();
song.sendSongInfo();
}
else if (strcmp(command, "PAUSE")==0){
song.pause();
song.sendSongInfo();
}
else if (strcmp(command, "NEXT_TRACK")==0){
boolean next = song.nextFile();
if (!next) {
handler.addKeyValuePair("message", "End of playlist");
}
}
else if (strcmp(command, "PREV_TRACK")==0){
boolean prev = song.prevFile();
if (!prev) {
handler.addKeyValuePair("message", "Begining of playlist");
}
}
else if (strcmp(command, "VOLUME") == 0) {
int volume = atoi(data);
double v = song.setVolume(volume);
}
else if (strcmp(command, "SEEK") == 0) {
int seek = song.seek(atoi(data));
handler.addKeyValuePair("position", seek);
}
else{
handler.addKeyValuePair("command", "MESSAGE",true);
handler.addKeyValuePair("message", "Command does not exist");
}
handler.respond();
}
song.loop();
}