Update Doorbell-Speaker.ino - läuft (sogar am Laptop-USB)

This commit is contained in:
2018-09-26 20:28:05 +00:00
parent 0ac7cc24b1
commit 6090dd7bf8
+12 -40
View File
@@ -17,14 +17,14 @@ https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
HardwareSerial mySoftwareSerial(1);
DFRobotDFPlayerMini myDFPlayer;
int volume = 10;
int volume = 8;
const char* ssid = "LeWe";
const char* password = "5275274365464843";
WiFiServer server(80); // Set web server port number to 80
String header;
String ledState = "off";
String ledState = "on";
const int ledPin = 26;
unsigned long timestamp = 0;
@@ -71,7 +71,6 @@ void setup()
}
else {
Serial.println(F("DFPlayer Mini online."));
digitalWrite(ledPin, HIGH);
myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms
myDFPlayer.volume(volume); //Set volume value (0~30).
@@ -112,53 +111,26 @@ void loop() {
// turns the GPIOs on and off
if (header.indexOf("GET /bell/on") >= 0) {
ledState = "on";
digitalWrite(ledPin, HIGH);
timestamp = millis();
myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms
//myDFPlayer.volume(12); //Set volume value (0~30).
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
myDFPlayer.play(1); //Play the first mp3
/*
if (myDFPlayer.available()) {
Serial.println("GPIO 26 on");
ledState = "on";
digitalWrite(ledPin, HIGH);
timestamp = millis();
if (myDFPlayer.readType() == DFPlayerPlayFinished) {
Serial.println(myDFPlayer.read());
Serial.println(F("next--------------------"));
// myDFPlayer.next(); //Play next mp3 every 3 second.
myDFPlayer.play(1); //Play the first mp3
Serial.println(F("readCurrentFileNumber--------------------"));
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
// delay(500);
}
}
else {
for (int i=0; i < 3; i++){
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}*/
}
else if (header.indexOf("GET /volume/") >= 0) { // yes, I know this is not RESTful
String str1 = header;
str1 = str1.substring(header.indexOf("GET /volume/") + 12);
volume = str1.substring(0, str1.indexOf(" ")).toInt();
if (volume >= 0 && volume <= 30) {
myDFPlayer.volume(volume);
Serial.print("volume set to ");
Serial.println(volume);
if (volume < 0) {
volume = 0;
}
else if (volume > 30) {
volume = 30;
}
myDFPlayer.volume(volume);
Serial.print("volume set to ");
Serial.println(volume);
}
// Display the HTML web page