Last active
August 29, 2015 14:06
-
-
Save karlentwistle/17fbfed8004b2536c46f 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
#include <Process.h> | |
void setup() // run once, when the sketch starts | |
{ | |
Bridge.begin(); | |
pinMode(2, OUTPUT); | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
} | |
void loop() // run over and over again | |
{ | |
String low = "low"; | |
String moderate = "moderate"; | |
String substantial = "substantial"; | |
String severe = "severe"; | |
String critical = "critical"; | |
if (threatLevel() == low) { | |
lightLED(2); | |
} else if (threatLevel() == moderate) { | |
lightLED(3); | |
} else if (threatLevel() == substantial) { | |
lightLED(4); | |
} else if (threatLevel() == severe) { | |
lightLED(5); | |
} else if (threatLevel() == critical) { | |
lightLED(6); | |
} else { | |
flashLEDS(); | |
} | |
delay(900000); | |
} | |
String threatLevel() { | |
Process p; | |
p.begin("curl"); | |
p.addParameter("http://threatlevel.herokuapp.com/"); | |
p.run(); | |
String threatLevel = ""; | |
while (p.available()>0) { | |
char c = p.read(); | |
threatLevel += c; | |
} | |
return threatLevel; | |
} | |
void lightLED(int pinNum) { | |
resetLEDS(); | |
digitalWrite(pinNum, HIGH); | |
} | |
void resetLEDS() { | |
digitalWrite(2, LOW); | |
digitalWrite(3, LOW); | |
digitalWrite(4, LOW); | |
digitalWrite(5, LOW); | |
digitalWrite(6, LOW); | |
} | |
void lightLEDS() { | |
digitalWrite(2, HIGH); | |
digitalWrite(3, HIGH); | |
digitalWrite(4, HIGH); | |
digitalWrite(5, HIGH); | |
digitalWrite(6, HIGH); | |
} | |
void flashLEDS() { | |
lightLEDS(); | |
delay(10); | |
resetLEDS(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment