Created
February 2, 2016 02:32
-
-
Save ryanmjacobs/41d84b4b08f37d4060fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
enum states_t { | |
WAIT, /* Wait until the soil is dry, then take action. */ | |
PUMP_BUFFER, /* Pump buffer reservoir until 90% capacity. */ | |
WATER_SOIL /* Water the soil until it isn't dry anymore. */ | |
}; | |
enum states_t state = WAIT; | |
while (1) { | |
switch (state) { | |
case WAIT: | |
if (soil_is_dry()) | |
state = WATER_SOIL; | |
sleep(1); | |
break; | |
case PUMP_BUFFER: | |
// pump water into buffer for 5 seconds | |
pump_buffer(5); | |
// buffer is at 90% capacity... go back to watering | |
if (buffer_level() > 90) | |
state = WATER_SOIL; | |
break; | |
case WATER_SOIL: | |
// buffer is close to empty... let's refill it | |
if (buffer_level() < 10) | |
state = PUMP_BUFFER; | |
// drip irrigate for 5 minutes | |
water_soil(5); | |
// done watering! | |
if (!soil_is_dry()) | |
state = WAIT; | |
break; | |
} | |
sleep(0.25); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment