Created
May 11, 2016 06:52
-
-
Save nippe/cb52fdddb26cc355dbb9c7db0a69266b 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
void loop() { | |
getWaterLevel(); | |
checkWaterLevel(); | |
delay(DELAY_IN_SECONDS * 1000); | |
} | |
int getWaterLevel() { | |
waterLevel = analogRead(waterLevelPin); | |
return waterLevel; | |
} | |
int sendSms(String command) { | |
if(command.length() > 0){ | |
Particle.publish("twilio", command, 60, PRIVATE); | |
} | |
return 0; | |
} | |
void checkWaterLevel() { | |
int currentLevel = analogRead(waterLevelPin); | |
if(currentLevel > waterThreshold) { | |
if(!isMessageSent){ | |
char msg[255]; | |
snprintf(msg, sizeof(msg), "Dags att tömma vatten i källarn! Nivå: %d", waterLevel); | |
sendSms(msg); | |
isMessageSent = true; | |
} | |
} | |
if(isMessageSent && (currentLevel < waterThreshold)) { | |
isMessageSent = false; | |
sendSms("Du har tömt ser jag, lysande polarn!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment