Created
April 21, 2015 21:52
-
-
Save objectiveSee/5dcff42df5a7d969d94f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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