|
@@ -44,6 +44,8 @@ AudioConnection patchCord7(mixer2, rms2);
|
|
|
AudioControlSGTL5000 sgtl5000_1; //xy=573,537
|
|
|
// GUItool: end automatically generated code
|
|
|
|
|
|
+int ID = 1 ;
|
|
|
+
|
|
|
bool UDPalive ;
|
|
|
|
|
|
Metro checkUDP = Metro(1000);
|
|
@@ -54,12 +56,13 @@ Metro sendRMS = Metro(50);
|
|
|
#define PRESENCE_WAV "PRESENCE.WAV"
|
|
|
#define WAIT_WAV "WAIT.WAV"
|
|
|
|
|
|
+
|
|
|
int WAIT_TIME=10000 ;
|
|
|
|
|
|
const int LDR_PIN = A7;
|
|
|
ResponsiveAnalogRead ldr(LDR_PIN, false);
|
|
|
-int threshold = 700;
|
|
|
-int hysteresis = 100;
|
|
|
+int threshold = 0;
|
|
|
+int hysteresis = 10;
|
|
|
int sensorPin = A7;
|
|
|
SetPoint setPoint;
|
|
|
|
|
@@ -116,6 +119,13 @@ void setup() {
|
|
|
delay(500);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ File configFile = SD.open("config.txt");
|
|
|
+ String buf = configFile.readStringUntil('\n');
|
|
|
+ ID = buf.toInt();
|
|
|
+ Serial.print("ID : ");
|
|
|
+ Serial.println(ID);
|
|
|
+ configFile.close();
|
|
|
Serial.println("Playing LOOP and WAIT file");
|
|
|
LoopPlayer.play(LOOP_WAV);
|
|
|
WaitPlayer.play(WAIT_WAV);
|
|
@@ -131,18 +141,36 @@ void setup() {
|
|
|
//ESP8266
|
|
|
Serial1.println("AT+GMR");
|
|
|
//while (!Serial1.available()) {};
|
|
|
- delay(200);
|
|
|
+ delay(200);
|
|
|
ESPSerial();
|
|
|
Serial.println("");
|
|
|
Serial.println("");
|
|
|
- while(millis()<10000){}
|
|
|
+ int sum ;
|
|
|
+ int counter ;
|
|
|
+ while(millis()<10000){ // wait for ESP to connect to its configured wifi
|
|
|
+ //make a mean value of LDR readings in between
|
|
|
+ ldr.update();
|
|
|
+ sum += ldr.getValue();
|
|
|
+ counter++;
|
|
|
+ delay(50);
|
|
|
+ }
|
|
|
+ threshold = sum / counter - hysteresis/2 ;
|
|
|
+ Serial.print("Threshold calibrated at : ");
|
|
|
+ Serial.println(threshold);
|
|
|
+ Serial.println(hysteresis/2);
|
|
|
|
|
|
Serial1.println("AT+CIFSR");
|
|
|
ESPSerial();
|
|
|
delay(200);
|
|
|
Serial.println ("");
|
|
|
- Serial1.println("AT+CIPSTART=\"UDP\",\"192.168.3.1\",8002");
|
|
|
+ int port = 8000 + ID;
|
|
|
+ Serial.print("AT+CIPSTART=\"UDP\",\"192.168.3.1\",");
|
|
|
+ Serial.println(port);
|
|
|
ESPSerial();
|
|
|
+ Serial.println ("");
|
|
|
+ setPoint.begin(threshold, hysteresis);
|
|
|
+ setPoint.attach(RISING_EDGE, Presence);
|
|
|
+ setPoint.attach(FALLING_EDGE, Absence);
|
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
@@ -222,12 +250,15 @@ void loop() {
|
|
|
LoopPlayer.play(LOOP_WAV);
|
|
|
// A brief delay for the library read WAV info
|
|
|
delay(10);
|
|
|
+ // also restarts WAIT file
|
|
|
+ WaitPlayer.play(WAIT_WAV);
|
|
|
+ delay(10);
|
|
|
}
|
|
|
|
|
|
if ( (millis() - LastPresence > WAIT_TIME) && !WaitPlayer.isPlaying() && !PresencePlayer.isPlaying()) {
|
|
|
- WaitPlayer.play(WAIT_WAV);
|
|
|
+
|
|
|
mixer1.gain (1, 1.0);
|
|
|
- Serial.println("Playing wait file");
|
|
|
+ Serial.println("Fading up wait file");
|
|
|
delay(10);
|
|
|
}
|
|
|
|
|
@@ -294,7 +325,7 @@ void Presence() {
|
|
|
Serial.println("Playing presence file");
|
|
|
}
|
|
|
|
|
|
- // if presence and playing, don't do anything
|
|
|
+ // if presence and playing, fade up to ensure
|
|
|
for (float fadeRamp ; fadeRamp < 100 ; fadeRamp++ ) {
|
|
|
mixer1.gain(0, fadeRamp/100) ;
|
|
|
}
|