Add reciever power

This commit is contained in:
2022-10-15 12:19:44 +03:00
parent 0aab4963c4
commit 5a1b30658d
6 changed files with 76 additions and 7 deletions

View File

@@ -38,6 +38,7 @@ extern "C" {
#define LED_R 13
#define LED_G 15
#define LED_B 2
#define RECIVER 18
#define TOPIC "home/bigroom/"
@@ -48,9 +49,10 @@ uint8_t timeLight;
byte levelBlue, levelWhite;
bool move, lightWhite;
float temp, hum;
bool bLamp, wLamp;
bool bLamp, wLamp, reciever;
uint8_t statLamp;
AsyncWebServer server(80);
#endif // __MAIN__

View File

@@ -77,6 +77,8 @@ void setup() {
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
pinMode(POWER, OUTPUT);
pinMode(RECIVER, OUTPUT);
ledcSetup(PWM_WHITE, 5000, 8);
ledcSetup(PWM_BLUE, 5000, 8);
ledcAttachPin(LED_WHITE, PWM_WHITE);
@@ -209,8 +211,8 @@ void loop() {
ledcWrite(PWM_BLUE, levBlue);
statLamp |= 0x01;
bLamp = true;
Serial.println(F("BLamp On"));
WebSerial.println(F("Blue Lamp On"));
//Serial.println(F("BLamp On"));
//WebSerial.println(F("Blue Lamp On"));
}
else if((LightLev > (spLight + dbLight)) || (move == 0)){
if((levRunB + 50 <= millis() && levBlue > 0)){
@@ -240,7 +242,7 @@ void loop() {
wLamp = false;
}
if(statLamp > 0) digitalWrite(POWER, HIGH);
else if((levBlue > 0) && (levWhite > 0)) digitalWrite(POWER, LOW);
else if((levBlue == 0) && (levWhite == 0)) digitalWrite(POWER, LOW);
if((cRun + 1000) <= millis()){ //Once per second
cRun = millis();
if(abs(LightLev - prevLLevel) > 100){
@@ -370,6 +372,7 @@ void onMqttConnect(bool sessionPresent) {
mqttClient.publish(TOPIC"spLevel", 1, false, s);
itoa(dbLight, s, 10);
mqttClient.publish(TOPIC"dbLevel", 1, false, s);
mqttClient.publish(TOPIC"reciever", 1, false, "0");
mqttClient.publish(TOPIC"lampw", 1, false, lightWhite ? "1" : "0");
mqttClient.publish(TOPIC"lampw_set", 1, false, lightWhite ? "1" : "0");
@@ -380,6 +383,7 @@ void onMqttConnect(bool sessionPresent) {
mqttClient.subscribe(TOPIC"moveperiod", 1);
mqttClient.subscribe(TOPIC"spLevel", 1);
mqttClient.subscribe(TOPIC"dbLevel", 1);
mqttClient.subscribe(TOPIC"reciever", 1);
Serial.print(F("PeriodMove:"));Serial.println(periodMotion);
Serial.print(F("SPLight:"));Serial.println(spLight);
@@ -449,6 +453,15 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
//EEPROM.put(0, levelBlue);
//w = true;
}
if(strcmp(topic, TOPIC"reciever") == 0){
reciever = atoi(pl);
digitalWrite(RECIVER, reciever);
Serial.printf("New Reciever: %d\n", lightWhite);
WebSerial.print("New Reciever: ");WebSerial.println(lightWhite);
//mqttClient.publish(TOPIC"reciever", 1, false, reciever ? "1" : "0");
//EEPROM.put(0, levelBlue);
//w = true;
}
if(strcmp(topic, TOPIC"moveperiod") == 0){
periodMotion = atoi(pl);
Serial.printf("New MovePeriod: %d\n", periodMotion);