#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; }