-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBottango_play_sound
57 lines (40 loc) · 1.42 KB
/
Bottango_play_sound
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
// Sound
#define DFPLAYER_RX 10 // Define RX PIN for DFPlayer
#define DFPLAYER_TX 11 // Define TX PIN for DFPlayer
SoftwareSerial softSerial(DFPLAYER_RX, DFPLAYER_TX);
#define FPSerial softSerial
DFRobotDFPlayerMini myDFPlayer;
.
.
.
void onEffectorRegistered(AbstractEffector *effector)
{
char effectorIdentifier[9];
effector->getIdentifier(effectorIdentifier, 9);
if (strcmp(effectorIdentifier, "snd1") == 0) {
FPSerial.begin(9600);
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(FPSerial, /*isACK = */true, /*doReset = */true)) { //Use serial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
}
}
.
.
.
void onTriggerCustomEventTriggered(AbstractEffector *effector)
{
char effectorIdentifier[9];
effector->getIdentifier(effectorIdentifier, 9);
if (strcmp(effectorIdentifier, "snd1") == 0) {
myDFPlayer.volume(20); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
}