Created
July 22, 2015 19:55
-
-
Save matt2005/1ee3ee9c0cd8f5f1bf82 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
// pumpOnInterval turn pump on for x | |
const unsigned long pumpOnInterval = (30 * 1000); | |
// pumpOffInterval turn pump off for x | |
const unsigned long pumpOffInterval = (60*60*1000); | |
// Which pins are connected to which LED/Pump | |
const byte pumpPin = 0; | |
const byte ledPin = 1; | |
// Variable holding the timer value so far. One for each "Timer" | |
unsigned long pumpTimer; | |
void setup() { | |
// set pumpPin to output | |
pinMode(pumpPin, OUTPUT); | |
pinMode(ledPin, OUTPUT); | |
// set off | |
digitalWrite (pumpPin, LOW); | |
digitalWrite (ledPin, LOW); | |
// Set timer | |
pumpTimer = millis (); | |
} | |
void pumpOn () | |
{ | |
// remember when we toggled it | |
pumpTimer = millis (); | |
while (millis() - pumpTimer < pumpOnInterval) { | |
digitalWrite (pumpPin, HIGH); | |
digitalWrite(ledPin, HIGH); | |
} | |
} // end of pumpOn | |
void pumpOff () | |
{ | |
digitalWrite (pumpPin, LOW); | |
toggleLED (); | |
} // end of pumpOff | |
// This function switches over the Led when is called | |
void toggleLED (void){ | |
if(digitalRead(ledPin)==HIGH){ digitalWrite(ledPin, LOW); } | |
else{ digitalWrite(ledPin, HIGH); } | |
delay(100); | |
} | |
void loop() { | |
// Turn pump on if millis - pumpTimer is greater than or equal to 1 hour | |
if ( (millis () - pumpTimer) >= pumpOffInterval) { | |
pumpOn (); | |
} | |
// Turn pump off | |
else { | |
pumpOff (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment