Skip to content

Instantly share code, notes, and snippets.

@objectiveSee
Created April 21, 2015 21:52
Show Gist options
  • Save objectiveSee/5dcff42df5a7d969d94f to your computer and use it in GitHub Desktop.
Save objectiveSee/5dcff42df5a7d969d94f to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include "Relay.h"
// Relay is active low, so you need a 0 to turn it on.
#define RELAY_ON 0
#define RELAY_OFF 1
Relay::Relay( int whatPin )
{
// initialize variables
pin = whatPin;
run = 0;
last_changed = millis();
// initialize physical objects
pinMode( pin, OUTPUT );
// don't forget that we don't know the state of the pin
// so give it one
digitalWrite( pin, RELAY_OFF );
}
void Relay::on()
{
if( ! run )
{
run = 1;
last_changed = millis();
}
digitalWrite( pin, RELAY_ON );
}
void Relay::off()
{
if ( run ) {
run = 0;
last_changed = millis();
}
digitalWrite( pin, RELAY_OFF );
}
int Relay::running()
{
return run;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment