-
Notifications
You must be signed in to change notification settings - Fork 1
/
MP3_BT_ESP32.ino
85 lines (77 loc) · 2.44 KB
/
MP3_BT_ESP32.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
75
76
77
78
79
80
81
82
83
84
85
/*****************************************************************************************************************************
********************************** Author : Ehab Magdy Abdullah *************************************
********************************** Linkedin: https://www.linkedin.com/in/ehabmagdyy/ *************************************
********************************** Youtube : https://www.youtube.com/@EhabMagdyy *************************************
******************************************************************************************************************************/
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "BluetoothSerial.h"
#define MP3_TX_PIN 17
#define MP3_RX_PIN 16
/* You can change it to number of songs you want to play in SD-Card */
#define NO_OF_AUDIO 4
/* MP3 Variables */
unsigned char audioNumber = 1;
unsigned char isPaused = 0;
unsigned char volume = 0;
/* Bluetooth variables */
String device_name = "ESP32-BT";
BluetoothSerial SerialBT;
unsigned char bt_value = 0;
SoftwareSerial softwareSerial(MP3_RX_PIN, MP3_TX_PIN);
DFRobotDFPlayerMini player;
void setup()
{
softwareSerial.begin(9600);
SerialBT.begin(device_name);
player.begin(softwareSerial);
player.volume(20);
player.play(1);
}
void loop()
{
/* Get bluetooth value */
if (SerialBT.available())
{
bt_value = SerialBT.read();
}
switch(bt_value)
{
/* play next audio */
case 'N':
/* play the next audio */
audioNumber = ((audioNumber + 1) > NO_OF_AUDIO)? 1 : (audioNumber + 1);
player.play(audioNumber);
break;
/* Pause/Resume audio */
case 'R':
if(isPaused)
{
player.start();
isPaused = 0;
}
else
{
player.pause();
isPaused = 1;
}
break;
/* play the previous audio */
case 'P':
audioNumber = ((audioNumber - 1) == 0)? NO_OF_AUDIO : (audioNumber - 1);
player.play(audioNumber);
break;
/* Change volume to 10 */
case 0x10:
player.volume(10);
break;
/* Change volume to 20 */
case 0x20:
player.volume(20);
break;
/* Change volume to 30 */
case 0x30:
player.volume(30);
break;
}
}