Update Doorbell-Speaker.ino - noch nicht schick, aber funktioniert inkl. Lautstärkeregelung
This commit is contained in:
+27
-3
@@ -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);
|
||||
|
||||
@@ -112,6 +113,18 @@ 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ürklingel</h1>");
|
||||
client.println("<body><h1>LeWe Tü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
|
||||
|
||||
Reference in New Issue
Block a user