KorMYS filter lightlevel

This commit is contained in:
2021-06-07 12:48:40 +03:00
parent a7641761fd
commit 2d0ce57744
4 changed files with 32 additions and 17 deletions

View File

@@ -8,10 +8,11 @@
#define MY_RADIO_RF24 #define MY_RADIO_RF24
#define MY_RF24_CHANNEL (105) #define MY_RF24_CHANNEL (105)
#define MY_RF24_PA_LEVEL RF24_PA_MAX #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_ERR_LED_PIN (A3) // Error led pin
#define MY_DEFAULT_RX_LED_PIN (5) // Receive led pin #define MY_DEFAULT_RX_LED_PIN (A2) // Receive led pin
#define MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED #define MY_DEFAULT_TX_LED_PIN (A1) // the PCB, on board LED
#include <MySensors.h> #include <MySensors.h>
#include <SoftwareSerial.h> // Remove if using HardwareSerial or non-uno compatabile device #include <SoftwareSerial.h> // Remove if using HardwareSerial or non-uno compatabile device
@@ -21,7 +22,7 @@
#define TX_PIN 7 #define TX_PIN 7
#define BAUDRATE 9600 #define BAUDRATE 9600
#define MOTION (7) #define MOTION (4)
#define LED_WHITE (5) #define LED_WHITE (5)
#define LED_BLUE (6) #define LED_BLUE (6)
MHZ19 myMHZ19; MHZ19 myMHZ19;
@@ -34,7 +35,6 @@ uint8_t curDelay;
uint8_t spLight, dbLight; uint8_t spLight, dbLight;
uint16_t levelBlue, levelWhite; uint16_t levelBlue, levelWhite;
bool move, lightWhite; bool move, lightWhite;
float temp, hum;
#endif #endif

View File

@@ -20,7 +20,7 @@ void setup() {
myMHZ19.begin(mySerial); // *Important, Pass your Stream reference here myMHZ19.begin(mySerial); // *Important, Pass your Stream reference here
myMHZ19.autoCalibration(false); myMHZ19.autoCalibration(false);
/* char myVersion[4]; char myVersion[4];
myMHZ19.getVersion(myVersion); myMHZ19.getVersion(myVersion);
Serial.print("\nFirmware Version: "); Serial.print("\nFirmware Version: ");
for(byte i = 0; i < 4; i++) for(byte i = 0; i < 4; i++)
@@ -37,7 +37,7 @@ void setup() {
Serial.println(myMHZ19.getBackgroundCO2()); Serial.println(myMHZ19.getBackgroundCO2());
Serial.print("Temperature Cal: "); Serial.print("Temperature Cal: ");
Serial.println(myMHZ19.getTempAdjustment()); 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); periodMinCO2 = loadState(0);
if(periodMinCO2 == 0) periodMinCO2 = 1; if(periodMinCO2 == 0) periodMinCO2 = 1;
periodMotion = loadState(1); periodMotion = loadState(1);
@@ -53,7 +53,6 @@ void loop() {
static uint32_t cRun = millis(); static uint32_t cRun = millis();
static uint8_t sec = 0; static uint8_t sec = 0;
static uint8_t minuts = 0; static uint8_t minuts = 0;
float temp, hum;
if(digitalRead(MOTION) > 0){ if(digitalRead(MOTION) > 0){
if(curDelay == -1) sendDataB(msgMove, true); if(curDelay == -1) sendDataB(msgMove, true);
@@ -86,6 +85,8 @@ void loop() {
if((sec + 2) % 30 == 0){ if((sec + 2) % 30 == 0){
temp = myHTU21D.readTemperature(); temp = myHTU21D.readTemperature();
hum = myHTU21D.readCompensatedHumidity(); hum = myHTU21D.readCompensatedHumidity();
Serial.println("Temp: " + String(temp));
Serial.println("Hum: " + String(hum));
} }
if(sec == 59){ if(sec == 59){
minuts++; minuts++;
@@ -101,7 +102,14 @@ void loop() {
sendDataI(msgCO2, CO2); sendDataI(msgCO2, CO2);
wait(50); wait(50);
} }
else{
Serial.println("CO2err:" + String(myMHZ19.errorCode));
}
if(temp != HTU21D_ERROR){ if(temp != HTU21D_ERROR){
Serial.println("Send");
Serial.println("Temp: " + String(temp));
Serial.println("Hum: " + String(hum));
sendDataF(msgTemp, temp); sendDataF(msgTemp, temp);
wait(50); wait(50);
sendDataF(msgHum, hum); sendDataF(msgHum, hum);

View File

@@ -12,5 +12,7 @@
platform = atmelavr platform = atmelavr
board = uno board = uno
framework = arduino framework = arduino
lib_deps = featherfly/SoftwareSerial @ ^1.0 lib_deps =
featherfly/SoftwareSerial @ ^1.0
robtillaart/RunningMedian @ ^0.3.3
monitor_speed = 115200 monitor_speed = 115200

View File

@@ -21,11 +21,14 @@
#include <MySensors.h> #include <MySensors.h>
#include <SDS011.h> #include <SDS011.h>
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
#include <RunningMedian.h>
unsigned long cRun; unsigned long cRun;
int cSec, adc, move, oldmov, minLight, minLightDB, LightInt, timeDelay, curDelay, fadeTime; int cSec, adc, move, oldmov, minLight, minLightDB, LightInt, timeDelay, curDelay, fadeTime;
uint8_t sdsPeriod; uint8_t sdsPeriod;
bool lamp; bool lamp;
RunningMedian samples = RunningMedian(5 * sizeof(int));
//float avgL; //float avgL;
#define RX_PIN 2 #define RX_PIN 2
#define TX_PIN 3 #define TX_PIN 3
@@ -98,7 +101,7 @@ void presentation()
void loop() void loop()
{ {
float p25, p10; float p25, p10;
uint32_t curTime; //uint32_t curTime;
if(digitalRead(PIN_MOVE) > 0){ if(digitalRead(PIN_MOVE) > 0){
if(curDelay == -1) sendData(msgMove, true); if(curDelay == -1) sendData(msgMove, true);
@@ -112,6 +115,8 @@ void loop()
// //send(msgMove.set(move)); // //send(msgMove.set(move));
// } // }
adc = analogRead(A0); adc = analogRead(A0);
samples.add(adc);
adc = samples.getMedian();
if ((adc <= minLight) && (move == 1)){ if ((adc <= minLight) && (move == 1)){
analogWrite(LAMP_OUT, LightInt); analogWrite(LAMP_OUT, LightInt);
if(lamp == false){ if(lamp == false){
@@ -139,7 +144,7 @@ void loop()
sendData(msgLamp, false); sendData(msgLamp, false);
//send(msgLamp.set(false)); //send(msgLamp.set(false));
lamp = false; lamp = false;
curTime = millis() + fadeTime * 1000 ; //curTime = millis() + fadeTime * 1000 ;
} }
} }
if(cRun + 999 < millis()){ if(cRun + 999 < millis()){
@@ -150,12 +155,12 @@ void loop()
curDelay = -1; curDelay = -1;
} }
if(curDelay > 0) curDelay--; if(curDelay > 0) curDelay--;
if(curDelay == 1) curTime = cRun + fadeTime * 1000; //if(curDelay == 1) curTime = cRun + fadeTime * 1000;
int error = sds.read(&p25, &p10); int error = sds.read(&p25, &p10);
if (!error) { if (!error) {
Serial.println(millis()/1000); // Serial.println(millis()/1000);
Serial.println("P2.5: " + String(p25)); // Serial.println("P2.5: " + String(p25));
Serial.println("P10: " + String(p10)); // Serial.println("P10: " + String(p10));
sendData(msgHum25, p25); sendData(msgHum25, p25);
wait(100); wait(100);
sendData(msgHum10, p10); sendData(msgHum10, p10);
@@ -165,7 +170,7 @@ void loop()
wait(100); wait(100);
sendData(msgLightLev, adc); sendData(msgLightLev, adc);
wait(100); wait(100);
uint32_t ms = millis(); uint32_t ms = millis() /1000;
send(msgMillis.set(ms)); send(msgMillis.set(ms));
} }
} }