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_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 <MySensors.h>
#include <SoftwareSerial.h> // 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

View File

@@ -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);

View File

@@ -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

View File

@@ -21,11 +21,14 @@
#include <MySensors.h>
#include <SDS011.h>
#include <SoftwareSerial.h>
#include <RunningMedian.h>
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));
}
}