Update Doorbell-Speaker.ino - noch nicht schick, aber funktioniert inkl. Lautstärkeregelung
This commit is contained in:
+26
-2
@@ -17,6 +17,7 @@ https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
|
|||||||
|
|
||||||
HardwareSerial mySoftwareSerial(1);
|
HardwareSerial mySoftwareSerial(1);
|
||||||
DFRobotDFPlayerMini myDFPlayer;
|
DFRobotDFPlayerMini myDFPlayer;
|
||||||
|
int volume = 10;
|
||||||
|
|
||||||
const char* ssid = "LeWe";
|
const char* ssid = "LeWe";
|
||||||
const char* password = "5275274365464843";
|
const char* password = "5275274365464843";
|
||||||
@@ -73,7 +74,7 @@ void setup()
|
|||||||
digitalWrite(ledPin, HIGH);
|
digitalWrite(ledPin, HIGH);
|
||||||
|
|
||||||
myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms
|
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.EQ(DFPLAYER_EQ_NORMAL);
|
||||||
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
|
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
|
||||||
|
|
||||||
@@ -112,6 +113,18 @@ void loop() {
|
|||||||
// turns the GPIOs on and off
|
// turns the GPIOs on and off
|
||||||
if (header.indexOf("GET /bell/on") >= 0) {
|
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()) {
|
if (myDFPlayer.available()) {
|
||||||
Serial.println("GPIO 26 on");
|
Serial.println("GPIO 26 on");
|
||||||
ledState = "on";
|
ledState = "on";
|
||||||
@@ -135,6 +148,16 @@ void loop() {
|
|||||||
digitalWrite(ledPin, LOW);
|
digitalWrite(ledPin, LOW);
|
||||||
delay(500);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +174,8 @@ void loop() {
|
|||||||
|
|
||||||
client.println("<body><h1>LeWe Türklingel</h1>");
|
client.println("<body><h1>LeWe Türklingel</h1>");
|
||||||
client.println("<p>LED - State " + ledState + "</p>");
|
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>");
|
client.println("</body></html>");
|
||||||
|
|
||||||
// The HTTP response ends with another blank line
|
// The HTTP response ends with another blank line
|
||||||
|
|||||||
Reference in New Issue
Block a user