evitar efecto rebote
parent
519b95a0f9
commit
6dfafd1390
|
|
@ -66,7 +66,7 @@ bool negado;
|
|||
val=!val;
|
||||
else
|
||||
val=(atoi(payload)==1);
|
||||
//cambia estado relle
|
||||
//cambia estado relleH
|
||||
if(negado)
|
||||
digitalWrite(pin, val==0);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -7,14 +7,19 @@ class SensorPulsante: public DomoEspSensorReceiver
|
|||
bool val;
|
||||
bool valDef;
|
||||
uint8_t pin;
|
||||
|
||||
unsigned long tiempo_sens;
|
||||
unsigned long incre_tsens;
|
||||
bool espera;
|
||||
public:
|
||||
virtual float getVal()
|
||||
{
|
||||
return (float)val;
|
||||
}
|
||||
SensorPulsante()
|
||||
{}
|
||||
{
|
||||
espera=false;
|
||||
incre_tsens=500;
|
||||
}
|
||||
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
||||
{
|
||||
pin=_pin;
|
||||
|
|
@ -22,10 +27,21 @@ class SensorPulsante: public DomoEspSensorReceiver
|
|||
val=valDef;
|
||||
strcpy(topic, topic_id);
|
||||
}
|
||||
void setIncremento(int milis)
|
||||
{
|
||||
incre_tsens=milis;
|
||||
}
|
||||
|
||||
virtual void procesa(IMqttManager * man, int tiempo)
|
||||
{
|
||||
//mirar para configurar por interrupcion
|
||||
int val_ac=digitalRead(pin);
|
||||
int val_ac=valDef;
|
||||
if(!espera || MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
||||
{
|
||||
val_ac=digitalRead(pin);
|
||||
espera=false;
|
||||
}
|
||||
|
||||
|
||||
if(val_ac!=val && val_ac!=valDef)
|
||||
{
|
||||
|
|
@ -36,7 +52,10 @@ class SensorPulsante: public DomoEspSensorReceiver
|
|||
sprintf(buffer_p, "%d", (int)val_ac);
|
||||
sprintf(buffer_t, "%s/pul",topic);
|
||||
man->MqttSend(buffer_t, buffer_p);
|
||||
delay(100);
|
||||
//delay(100);
|
||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
espera=true;
|
||||
|
||||
}
|
||||
val=val_ac;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue