KorMYS filter lightlevel
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user