diff --git a/BigRoomMyS/platformio.ini b/BigRoomMyS/platformio.ini index b6d361d..e881e68 100644 --- a/BigRoomMyS/platformio.ini +++ b/BigRoomMyS/platformio.ini @@ -16,5 +16,5 @@ monitor_speed = 115200 lib_deps = MySensors @ ^2.3.2 wifwaf/MH-Z19 @ ^1.5.3 - enjoyneering/AHT10 @ ^1.1.0 + enjoyneering/HTU21D @ ^1.2.1 featherfly/SoftwareSerial @ ^1.0 \ No newline at end of file diff --git a/KorMYS/src/main.cpp b/KorMYS/src/main.cpp index 9b63da1..59769af 100644 --- a/KorMYS/src/main.cpp +++ b/KorMYS/src/main.cpp @@ -23,7 +23,7 @@ #include unsigned long cRun; -int cSec, adc, move, oldmov, minLight, minLightDB, LightInt, timeDelay, curDelay; +int cSec, adc, move, oldmov, minLight, minLightDB, LightInt, timeDelay, curDelay, fadeTime; uint8_t sdsPeriod; bool lamp; //float avgL; @@ -67,6 +67,7 @@ void setup() LightInt = (loadState(4) << 8) + loadState(5); sdsPeriod = loadState(6); timeDelay = (loadState(8) << 8) + loadState(9); + fadeTime = (loadState(10) << 8) + loadState(11); curDelay = -1; Serial.print(F("Min Light"));Serial.println(minLight); Serial.print(F("Min LightDB"));Serial.println(minLightDB); @@ -96,6 +97,7 @@ void presentation() void loop() { float p25, p10; + uint32_t curTime; //move = digitalRead(A1); if(digitalRead(A1) > 0){ @@ -125,7 +127,8 @@ void loop() } } else if((adc > (minLight + minLightDB)) || (move == 0)){ - analogWrite(LAMP_OUT, 0); + //analogWrite(LAMP_OUT, 0); + curDelay = 2; if(lamp == true){ Serial.println("Lamp OFF"); Serial.print("ADC: ");Serial.print(adc); @@ -136,6 +139,7 @@ void loop() sendData(msgLamp, false); //send(msgLamp.set(false)); lamp = false; + curTime = millis() + fadeTime * 1000 ; } } if(cRun + 999 < millis()){ @@ -146,28 +150,33 @@ void loop() curDelay = -1; } if(curDelay > 0) curDelay--; + if(curDelay == 1) curTime = cRun + fadeTime * 1000; int error = sds.read(&p25, &p10); - //Serial.print("ADC: ");Serial.print(adc);Serial.print(", Move: ");Serial.println(move); if (!error) { Serial.println(millis()/1000); Serial.println("P2.5: " + String(p25)); Serial.println("P10: " + String(p10)); sendData(msgHum25, p25); - //send(msgHum25.set(p25, 1)); wait(100); sendData(msgHum10, p10); - //send(msgHum10.set(p10, 1)); } if (++cSec > 19){ cSec = 0; wait(100); sendData(msgLightLev, adc); - //send(msgLightLev.set(adc)); wait(100); uint32_t ms = millis(); send(msgMillis.set(ms)); } } + if(lamp && curTime > millis()){ + uint8_t ll = int(LightInt - LightInt * (1 - curTime - millis() / float(fadeTime * 1000))); + analogWrite(LAMP_OUT, ll); + if(curTime - millis() < 10){ + lamp = false; + analogWrite(LAMP_OUT, 0); + } + } } void receive(const MyMessage &message) @@ -207,6 +216,13 @@ void receive(const MyMessage &message) Serial.print("time period:"); Serial.println(timeDelay); } + if((message.sensor == 5) && (message.type == V_VAR3)){ + fadeTime = message.getInt(); + saveState(10, (fadeTime>>8) & 0xFF); + saveState(11, fadeTime & 0xFF); + Serial.print("fade period:"); + Serial.println(fadeTime); + } } ////////////////// sends work mode command to SDS011 //////////////////////