void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int value = analogRead(A1);
if(value != 0){
callVoice(value);
}
delay(200);
}
void callVoice(int result){
if (result >= 478 && result <= 481){
Serial.print("A ");
Serial.println(result);
}else if(result >= 488 && result <= 491){
Serial.print("B ");
Serial.println(result);
}else if(result >= 498 && result <= 501){
Serial.print("C ");
Serial.println(result);
}
}
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void setup() {
mySoftwareSerial.begin(9600);
Serial.begin(115200);
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
myDFPlayer.volume(12); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
void loop() {
}
FINNAL
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void setup() {
mySoftwareSerial.begin(9600);
Serial.begin(9600);//115200 ||
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
myDFPlayer.volume(20); //Set volume value. From 0 to 30
}
void loop() {
int value = analogRead(A0);
if(value != 0){
callVoice(value);
}
delay(200);
}
void callVoice(int result){
if (result >= 478 && result <= 481){
Serial.println("001");
myDFPlayer.play(1);
}else if(result >= 488 && result <= 491){
Serial.println("002");
myDFPlayer.play(2);
}else if(result >= 498 && result <= 501){
Serial.println("003");
myDFPlayer.play(3);
}else if(result >= 974 && result <= 977){
Serial.println("004");
myDFPlayer.play(4);
}else if(result >= 1014 && result <= 1017){
Serial.println("005");
myDFPlayer.play(5);
}
}