BR add led
This commit is contained in:
40
BigRoomMyS/include/main.h
Normal file
40
BigRoomMyS/include/main.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef __MAIN__
|
||||
#define __MAIN__
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include "MHZ19.h"
|
||||
|
||||
#define MY_DEBUG
|
||||
#define MY_RADIO_RF24
|
||||
#define MY_RF24_CHANNEL (105)
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
||||
|
||||
#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
|
||||
|
||||
#include <MySensors.h>
|
||||
#include <SoftwareSerial.h> // Remove if using HardwareSerial or non-uno compatabile device
|
||||
#include <HTU21D.h>
|
||||
|
||||
#define RX_PIN 8
|
||||
#define TX_PIN 7
|
||||
#define BAUDRATE 9600
|
||||
|
||||
#define MOTION (7)
|
||||
#define LED_WHITE (5)
|
||||
#define LED_BLUE (6)
|
||||
MHZ19 myMHZ19;
|
||||
SoftwareSerial mySerial(RX_PIN, TX_PIN);
|
||||
HTU21D myHTU21D(HTU21D_RES_RH10_TEMP13);
|
||||
|
||||
uint8_t periodMinCO2;
|
||||
uint8_t periodMotion;
|
||||
uint8_t curDelay;
|
||||
uint8_t spLight, dbLight;
|
||||
uint16_t levelBlue, levelWhite;
|
||||
bool move, lightWhite;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,32 +1,4 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <AHT10.h>
|
||||
#include "MHZ19.h"
|
||||
|
||||
#define MY_DEBUG
|
||||
#define MY_RADIO_RF24
|
||||
#define MY_RF24_CHANNEL (105)
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
||||
|
||||
#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
|
||||
|
||||
#include <MySensors.h>
|
||||
#include <SoftwareSerial.h> // Remove if using HardwareSerial or non-uno compatabile device
|
||||
|
||||
#define RX_PIN 8
|
||||
#define TX_PIN 7
|
||||
#define BAUDRATE 9600
|
||||
|
||||
#define MOTION (6)
|
||||
|
||||
MHZ19 myMHZ19;
|
||||
SoftwareSerial mySerial(RX_PIN, TX_PIN);
|
||||
|
||||
uint8_t periodMin;
|
||||
uint8_t periodMotion;
|
||||
uint8_t curDelay;
|
||||
#include "main.h"
|
||||
|
||||
void presentation();
|
||||
void sendDataI(MyMessage msg, uint32_t status);
|
||||
@@ -66,25 +38,60 @@ void setup() {
|
||||
Serial.print("Temperature Cal: ");
|
||||
Serial.println(myMHZ19.getTempAdjustment());
|
||||
Serial.print("ABC Status: "); myMHZ19.getABC() ? Serial.println("ON") : Serial.println("OFF");*/
|
||||
periodMin = loadState(0);
|
||||
if(periodMin == 0) periodMin = 1;
|
||||
periodMinCO2 = loadState(0);
|
||||
if(periodMinCO2 == 0) periodMinCO2 = 1;
|
||||
periodMotion = loadState(1);
|
||||
if(periodMotion == 0) periodMotion = 60;
|
||||
spLight = (loadState(2) << 8) + loadState(3);
|
||||
spLight = (loadState(4) << 8) + loadState(5);
|
||||
levelBlue = (loadState(6) << 8) + loadState(7);
|
||||
levelWhite = (loadState(8) << 8) + loadState(9);
|
||||
myHTU21D.begin();
|
||||
}
|
||||
|
||||
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);
|
||||
move = true;
|
||||
curDelay = periodMotion;
|
||||
}
|
||||
|
||||
uint16_t LightLev = analogRead(A0);
|
||||
if (LightLev < spLight && move){
|
||||
analogWrite(LED_BLUE, levelBlue);
|
||||
}
|
||||
else if((LightLev > (spLight + dbLight)) || (move == 0)){
|
||||
analogWrite(LED_BLUE, 0);
|
||||
}
|
||||
|
||||
if(lightWhite)
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
else
|
||||
analogWrite(LED_WHITE, 0);
|
||||
|
||||
if((cRun + 1000) <= millis()){ //Once per second
|
||||
cRun = millis();
|
||||
sec++;
|
||||
if(curDelay > 0) curDelay--;
|
||||
if(curDelay == 0){
|
||||
sendDataB(msgMove, false);
|
||||
move = false;
|
||||
curDelay = -1;
|
||||
}
|
||||
if((sec + 2) % 30 == 0){
|
||||
temp = myHTU21D.readTemperature();
|
||||
hum = myHTU21D.readCompensatedHumidity();
|
||||
}
|
||||
if(sec == 59){
|
||||
minuts++;
|
||||
sec = 0;
|
||||
}
|
||||
if(minuts == periodMin){
|
||||
if(minuts == periodMinCO2){
|
||||
int CO2; // Buffer for CO2
|
||||
CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
|
||||
|
||||
@@ -94,6 +101,12 @@ void loop() {
|
||||
sendDataI(msgCO2, CO2);
|
||||
wait(50);
|
||||
}
|
||||
if(temp != HTU21D_ERROR){
|
||||
sendDataF(msgTemp, temp);
|
||||
wait(50);
|
||||
sendDataF(msgHum, hum);
|
||||
wait(50);
|
||||
}
|
||||
sendDataI(msgTimeWork, cRun);
|
||||
minuts = 0;
|
||||
}
|
||||
@@ -116,8 +129,8 @@ void receive(const MyMessage &message)
|
||||
saveState(1, periodMotion);
|
||||
}
|
||||
if((message.sensor == 3) && (message.type == V_VAR5)){
|
||||
periodMin = message.getByte();
|
||||
saveState(0, periodMin);
|
||||
periodMinCO2 = message.getByte();
|
||||
saveState(0, periodMinCO2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user