adventsfenster/include/relais.h

75 lines
1.1 KiB
C
Raw Normal View History

2021-11-03 17:55:42 +01:00
#ifndef __relais_H__
#define __relais_H__
#include <Arduino.h>
class relais
{
private:
size_t _ctrl_pin;
bool _relais_on = false;
public:
relais(size_t ctrl_pin);
~relais();
void on();
void off();
void toggle();
bool is_on();
2021-12-08 18:25:51 +01:00
void begin();
2021-11-03 17:55:42 +01:00
};
relais::relais(size_t ctrl_pin)
{
_ctrl_pin = ctrl_pin;
_relais_on = false;
2021-12-08 18:25:51 +01:00
}
void relais::begin()
{
2021-11-03 17:55:42 +01:00
pinMode(_ctrl_pin, OUTPUT);
2021-12-08 18:25:51 +01:00
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
2021-11-03 17:55:42 +01:00
}
relais::~relais()
{
}
void relais::on()
{
2021-12-08 18:25:51 +01:00
if(_relais_on == false)
{
digitalWrite(_ctrl_pin, LOW);
_relais_on = true;
}
2021-11-03 17:55:42 +01:00
}
void relais::off()
{
2021-12-08 18:25:51 +01:00
if(_relais_on == true)
{
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
}
2021-11-03 17:55:42 +01:00
}
void relais::toggle()
{
if(true == _relais_on)
{
2021-11-08 13:18:06 +01:00
digitalWrite(_ctrl_pin, HIGH);
2021-11-03 17:55:42 +01:00
_relais_on = false;
}
else
{
2021-11-08 13:18:06 +01:00
digitalWrite(_ctrl_pin, LOW);
2021-11-03 17:55:42 +01:00
_relais_on = true;
}
}
bool relais::is_on()
{
return(_relais_on);
}
#endif