adventsfenster/include/relais.h
2021-12-08 18:25:51 +01:00

75 lines
No EOL
1.1 KiB
C++

#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();
void begin();
};
relais::relais(size_t ctrl_pin)
{
_ctrl_pin = ctrl_pin;
_relais_on = false;
}
void relais::begin()
{
pinMode(_ctrl_pin, OUTPUT);
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
}
relais::~relais()
{
}
void relais::on()
{
if(_relais_on == false)
{
digitalWrite(_ctrl_pin, LOW);
_relais_on = true;
}
}
void relais::off()
{
if(_relais_on == true)
{
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
}
}
void relais::toggle()
{
if(true == _relais_on)
{
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
}
else
{
digitalWrite(_ctrl_pin, LOW);
_relais_on = true;
}
}
bool relais::is_on()
{
return(_relais_on);
}
#endif