Update Doorbell-Speaker.ino - noch nicht schick, aber funktioniert inkl. Lautstärkeregelung

This commit is contained in:
2018-09-26 20:13:39 +00:00
parent 405c0d58c6
commit 0ac7cc24b1
+27 -3
View File
@@ -17,6 +17,7 @@ https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
HardwareSerial mySoftwareSerial(1);
DFRobotDFPlayerMini myDFPlayer;
int volume = 10;
const char* ssid = "LeWe";
const char* password = "5275274365464843";
@@ -73,7 +74,7 @@ void setup()
digitalWrite(ledPin, HIGH);
myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms
myDFPlayer.volume(12); //Set volume value (0~30).
myDFPlayer.volume(volume); //Set volume value (0~30).
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
@@ -111,7 +112,19 @@ 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";
@@ -135,6 +148,16 @@ void loop() {
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);
}
}
@@ -149,9 +172,10 @@ void loop() {
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");
client.println("<body><h1>LeWe T&uuml;rklingel</h1>");
client.println("<body><h1>LeWe T&uuml;rklingel</h1>");
client.println("<p>LED - State " + ledState + "</p>");
client.println("<p><a href=\"/bell/on\"><button class=\"button\">ON</button></a></p>");
client.println("<p>Volume " + String(volume) + "</p>");
client.println("<p><a href=\"/bell/on\"><button class=\"button\">Klingeln</button></a></p>");
client.println("</body></html>");
// The HTTP response ends with another blank line