diff --git a/BigRoomMyS/include/main.h b/BigRoomMyS/include/main.h index d0686cd..1cc9691 100644 --- a/BigRoomMyS/include/main.h +++ b/BigRoomMyS/include/main.h @@ -8,10 +8,11 @@ #define MY_RADIO_RF24 #define MY_RF24_CHANNEL (105) #define MY_RF24_PA_LEVEL RF24_PA_MAX +//#define MY_REPEATER_FEATURE -#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin -#define MY_DEFAULT_RX_LED_PIN (5) // Receive led pin -#define MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED +#define MY_DEFAULT_ERR_LED_PIN (A3) // Error led pin +#define MY_DEFAULT_RX_LED_PIN (A2) // Receive led pin +#define MY_DEFAULT_TX_LED_PIN (A1) // the PCB, on board LED #include #include // Remove if using HardwareSerial or non-uno compatabile device @@ -21,7 +22,7 @@ #define TX_PIN 7 #define BAUDRATE 9600 -#define MOTION (7) +#define MOTION (4) #define LED_WHITE (5) #define LED_BLUE (6) MHZ19 myMHZ19; @@ -34,7 +35,6 @@ uint8_t curDelay; uint8_t spLight, dbLight; uint16_t levelBlue, levelWhite; bool move, lightWhite; - - +float temp, hum; #endif \ No newline at end of file diff --git a/BigRoomMyS/src/main.cpp b/BigRoomMyS/src/main.cpp index 24d7821..21ec851 100644 --- a/BigRoomMyS/src/main.cpp +++ b/BigRoomMyS/src/main.cpp @@ -20,7 +20,7 @@ void setup() { myMHZ19.begin(mySerial); // *Important, Pass your Stream reference here myMHZ19.autoCalibration(false); -/* char myVersion[4]; + char myVersion[4]; myMHZ19.getVersion(myVersion); Serial.print("\nFirmware Version: "); for(byte i = 0; i < 4; i++) @@ -37,7 +37,7 @@ void setup() { Serial.println(myMHZ19.getBackgroundCO2()); Serial.print("Temperature Cal: "); Serial.println(myMHZ19.getTempAdjustment()); - Serial.print("ABC Status: "); myMHZ19.getABC() ? Serial.println("ON") : Serial.println("OFF");*/ + Serial.print("ABC Status: "); myMHZ19.getABC() ? Serial.println("ON") : Serial.println("OFF"); periodMinCO2 = loadState(0); if(periodMinCO2 == 0) periodMinCO2 = 1; periodMotion = loadState(1); @@ -53,7 +53,6 @@ void loop() { static uint32_t cRun = millis(); static uint8_t sec = 0; static uint8_t minuts = 0; - float temp, hum; if(digitalRead(MOTION) > 0){ if(curDelay == -1) sendDataB(msgMove, true); @@ -86,6 +85,8 @@ void loop() { if((sec + 2) % 30 == 0){ temp = myHTU21D.readTemperature(); hum = myHTU21D.readCompensatedHumidity(); + Serial.println("Temp: " + String(temp)); + Serial.println("Hum: " + String(hum)); } if(sec == 59){ minuts++; @@ -101,7 +102,14 @@ void loop() { sendDataI(msgCO2, CO2); wait(50); } + else{ + Serial.println("CO2err:" + String(myMHZ19.errorCode)); + } if(temp != HTU21D_ERROR){ + Serial.println("Send"); + + Serial.println("Temp: " + String(temp)); + Serial.println("Hum: " + String(hum)); sendDataF(msgTemp, temp); wait(50); sendDataF(msgHum, hum); diff --git a/KorMYS/platformio.ini b/KorMYS/platformio.ini index f8c6aa7..28837b6 100644 --- a/KorMYS/platformio.ini +++ b/KorMYS/platformio.ini @@ -12,5 +12,7 @@ platform = atmelavr board = uno framework = arduino -lib_deps = featherfly/SoftwareSerial @ ^1.0 +lib_deps = + featherfly/SoftwareSerial @ ^1.0 + robtillaart/RunningMedian @ ^0.3.3 monitor_speed = 115200 diff --git a/KorMYS/src/main.cpp b/KorMYS/src/main.cpp index f52c847..b684ac0 100644 --- a/KorMYS/src/main.cpp +++ b/KorMYS/src/main.cpp @@ -21,11 +21,14 @@ #include #include #include +#include unsigned long cRun; int cSec, adc, move, oldmov, minLight, minLightDB, LightInt, timeDelay, curDelay, fadeTime; uint8_t sdsPeriod; bool lamp; +RunningMedian samples = RunningMedian(5 * sizeof(int)); + //float avgL; #define RX_PIN 2 #define TX_PIN 3 @@ -98,7 +101,7 @@ void presentation() void loop() { float p25, p10; - uint32_t curTime; + //uint32_t curTime; if(digitalRead(PIN_MOVE) > 0){ if(curDelay == -1) sendData(msgMove, true); @@ -112,6 +115,8 @@ void loop() // //send(msgMove.set(move)); // } adc = analogRead(A0); + samples.add(adc); + adc = samples.getMedian(); if ((adc <= minLight) && (move == 1)){ analogWrite(LAMP_OUT, LightInt); if(lamp == false){ @@ -139,7 +144,7 @@ void loop() sendData(msgLamp, false); //send(msgLamp.set(false)); lamp = false; - curTime = millis() + fadeTime * 1000 ; + //curTime = millis() + fadeTime * 1000 ; } } if(cRun + 999 < millis()){ @@ -150,12 +155,12 @@ void loop() curDelay = -1; } if(curDelay > 0) curDelay--; - if(curDelay == 1) curTime = cRun + fadeTime * 1000; + //if(curDelay == 1) curTime = cRun + fadeTime * 1000; int error = sds.read(&p25, &p10); if (!error) { - Serial.println(millis()/1000); - Serial.println("P2.5: " + String(p25)); - Serial.println("P10: " + String(p10)); + // Serial.println(millis()/1000); + // Serial.println("P2.5: " + String(p25)); + // Serial.println("P10: " + String(p10)); sendData(msgHum25, p25); wait(100); sendData(msgHum10, p10); @@ -165,7 +170,7 @@ void loop() wait(100); sendData(msgLightLev, adc); wait(100); - uint32_t ms = millis(); + uint32_t ms = millis() /1000; send(msgMillis.set(ms)); } }