Переглянути джерело

fixed issue with threshold

problem with int calculation (solved with floating point...)
problem with calibration regarding hysteresis
Etienne Landon 8 роки тому
батько
коміт
65ea42672b
1 змінених файлів з 10 додано та 9 видалено
  1. 10 9
      I_Mihalache_AudioPlayer.ino

+ 10 - 9
I_Mihalache_AudioPlayer.ino

@@ -61,8 +61,8 @@ int WAIT_TIME=10000 ;
 
 const int LDR_PIN = A7;
 ResponsiveAnalogRead ldr(LDR_PIN, false);
-int threshold = 0;
-int hysteresis = 10;
+float threshold = 935;
+float hysteresis = 5;
 int sensorPin = A7;
 SetPoint setPoint;
 
@@ -145,27 +145,26 @@ void setup() {
   ESPSerial();  
   Serial.println("");
   Serial.println("");
-  int sum ;
-  int counter ;
+  float sum ;
+  float 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);
+     delay(100);
     }
-    threshold = sum / counter - hysteresis/2 ;
+    threshold = sum / counter + hysteresis ;
   Serial.print("Threshold calibrated at : ");
   Serial.println(threshold);
-  Serial.println(hysteresis/2);
   
   Serial1.println("AT+CIFSR");
   ESPSerial();
   delay(200);
   Serial.println ("");
   int port = 8000 + ID;
-  Serial.print("AT+CIPSTART=\"UDP\",\"192.168.3.1\",");
-  Serial.println(port);
+  Serial1.print("AT+CIPSTART=\"UDP\",\"192.168.3.1\",");
+  Serial1.println(port);
   ESPSerial();
   Serial.println ("");
   setPoint.begin(threshold, hysteresis);
@@ -241,6 +240,7 @@ void loop() {
 
   ldr.update();
   int value = ldr.getValue();
+  //Serial.println(value);
   setPoint.update(value);
 
 
@@ -269,6 +269,7 @@ void loop() {
   if (millis()-LastPresence > WAIT_TIME && PresencePlayer.isPlaying() && presence == false) {
     Serial.println("Stopping PRESENCE file");
     PresencePlayer.stop();
+    Serial.println("Fading up WAIT file");
     for (float fadeRamp ; fadeRamp < 100 ; fadeRamp++ ) {
           mixer1.gain(1, fadeRamp/100) ;
         }