Update sketch_oct11a.ino
This commit is contained in:
parent
eaeafd35b9
commit
aa03dd5dce
|
@ -1,85 +1,87 @@
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
const char* ssid = "CTDO-g";
|
const char* ssid = "CTDO-g"; //Netzwerk Name
|
||||||
const char* password = "ctdo2342";
|
const char* password = "ctdo2342"; //Wifi Passwort
|
||||||
const char* host = "rpi3.raum.ctdo.de";
|
const char* host = "rpi3.raum.ctdo.de"; //MPD Host
|
||||||
const int httpPort = 6600;
|
const int httpPort = 6600; //MPD Port
|
||||||
const int buttonPin = 5;
|
const int buttonPin = 5; //Pin vom Mikrocontroller
|
||||||
|
|
||||||
int buttonState;
|
int buttonState;
|
||||||
bool previousState;
|
bool previousState;
|
||||||
int previousMillis;
|
int previousMillis;
|
||||||
int currentMillis;
|
int currentMillis;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200); //Open the Serail Connection for Debugging
|
||||||
delay(10);
|
delay(10);
|
||||||
pinMode(buttonPin, INPUT);
|
pinMode(buttonPin, INPUT); //Set the Pin to INPUT for checking the Status
|
||||||
|
|
||||||
Serial.print("Connecting to ");
|
Serial.print("Connecting to "); //Print the SSID
|
||||||
Serial.println(ssid);
|
Serial.println(ssid);
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA); //Open the Wifi connection
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print("."); //Print Dots while Connecting
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println("WiFi connected");
|
Serial.println("WiFi connected"); //Selfexplaining
|
||||||
Serial.println("IP address: ");
|
Serial.println("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
currentMillis = millis();
|
currentMillis = millis(); //Save the current Time
|
||||||
buttonState = digitalRead(buttonPin);
|
buttonState = digitalRead(buttonPin); //Check the Pin Status
|
||||||
|
|
||||||
if (currentMillis - previousMillis > 500) {
|
if (currentMillis - previousMillis > 500) { //Atleast all 500 Milliseconds
|
||||||
if (buttonState == HIGH && previousState == false) {
|
if (buttonState == HIGH && previousState == false) { //If Button pressed
|
||||||
mpdbass(true);
|
mpdbass(true); //Make Bass
|
||||||
previousState = true;
|
previousState = true;
|
||||||
} else if (buttonState == LOW && previousState == true) {
|
} else if (buttonState == LOW && previousState == true) { //If Button released
|
||||||
mpdbass(false);
|
mpdbass(false); //stop Bass
|
||||||
previousState = false;
|
previousState = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpdbass(bool start) {
|
void mpdbass(bool start) {
|
||||||
WiFiClient client;
|
WiFiClient client; //Open Connection
|
||||||
if (!client.connect(host, httpPort)) {
|
if (!client.connect(host, httpPort)) { //When not connected
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed"); //Error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long timeout = millis();
|
unsigned long timeout = millis();
|
||||||
while (client.available() == 0) {
|
while (client.available() == 0) { //While not connected
|
||||||
if (millis() - timeout > 5000) {
|
if (millis() - timeout > 5000) { //If 5 seconds
|
||||||
Serial.println(">>> Client Timeout !");
|
Serial.println(">>> Client Timeout !"); // Timeout
|
||||||
client.stop();
|
client.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(client.available()){
|
while(client.available()){ //Print Client Foo
|
||||||
String line = client.readStringUntil('\r');
|
String line = client.readStringUntil('\r');
|
||||||
Serial.print(line);
|
Serial.print(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start == true){
|
if (start == true){ //If Button pressed
|
||||||
Serial.println("Play");
|
Serial.println("Play");
|
||||||
client.println("addid \"users/lucas/Alben/Function/Incubation/01 Voiceprint.flac\" 0");
|
client.println("addid \"users/lucas/Alben/Function/Incubation/01 Voiceprint.flac\" 0"); //Adds the Song as First Song
|
||||||
client.println("play 0");
|
client.println("setvol 100"); //set Max volume
|
||||||
|
client.println("play 0"); //Play the First song
|
||||||
} else if (start == false) {
|
} else if (start == false) {
|
||||||
Serial.println("Remove");
|
Serial.println("Remove");
|
||||||
client.println("delete 0");
|
client.println("delete 0"); //Remove the first Song (The Bass Song)
|
||||||
|
client.println("setvol 60"); //Set back to 60
|
||||||
}
|
}
|
||||||
|
|
||||||
while(client.available()){
|
while(client.available()){ //Print Client Foo
|
||||||
String line = client.readStringUntil('\r');
|
String line = client.readStringUntil('\r');
|
||||||
Serial.print(line);
|
Serial.print(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue