add switching logic

This commit is contained in:
Torsten Ruger 2021-07-04 22:17:28 +03:00
parent 2cb5cb0363
commit 90c0ee3e1d
2 changed files with 20 additions and 3 deletions

View File

@ -21,12 +21,12 @@ protected:
float minute_in = 0 ;
float minute_out = 0 ;
int minute_counter = 0;
int week_counter = 0;
int month_counter = 0;
void add_month(int from ) ;
void switch_logic(float in , float out);
public:
float week_in[WEEK];

View File

@ -21,6 +21,8 @@ WsSerial debug_out;
DHT dht_in(1, DHT11); // D2 on mini , tx, 01 on basic
DHT dht_out(3, DHT11); // D1 on mini , rx 03 on basic
#define RELAY 12 // the relay pin
Collector collector;
float next_rand( float old ){
@ -57,8 +59,8 @@ void collector_loop(){
void Collector::add(float in , float out)
{
if(isnan(in) ) return ;
if(isnan(out) ) return ;
if(isnan(in) ) return ;
if(isnan(out) ) return ;
minute_in += in;
minute_out += out;
minute_counter++ ;
@ -70,7 +72,22 @@ void Collector::add(float in , float out)
}
}
void Collector::switch_logic(float in , float out){
u_int8_t on;
String msg;
if(in < out){
on = 1 ;
msg = "Switching on";
}else{
on = 0 ;
msg = "Switching off";
}
digitalWrite( RELAY , on);
DEBUG_OUT.println(msg);
}
void Collector::add_week(float in , float out){
switch_logic(in , out);
week_in[week_counter] = in;
week_out[week_counter] = out;
if((week_counter % PER_HOUR) == 0){