You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
604 B
32 lines
604 B
4 years ago
|
#include "relay.h"
|
||
|
|
||
|
Relay::Relay(byte pin) {
|
||
|
// Use 'this->' to make the difference between the
|
||
|
// 'pin' attribute of the class and the
|
||
|
// local variable 'pin' created from the parameter.
|
||
|
this->pin = pin;
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
void Relay::init() {
|
||
|
pinMode(pin, OUTPUT);
|
||
|
// Always try to avoid duplicate code.
|
||
|
// Instead of writing digitalWrite(pin, LOW) here,
|
||
|
// call the function off() which already does that
|
||
|
off();
|
||
|
}
|
||
|
|
||
|
void Relay::on() {
|
||
|
digitalWrite(pin, LOW);
|
||
|
state = LOW;
|
||
|
}
|
||
|
|
||
|
void Relay::off() {
|
||
|
digitalWrite(pin, HIGH);
|
||
|
state = HIGH;
|
||
|
}
|
||
|
|
||
|
bool Relay::getState() {
|
||
|
return !state;
|
||
|
}
|