Skip to content

Instantly share code, notes, and snippets.

@ersatzavian
Created April 25, 2015 21:34
Show Gist options
  • Save ersatzavian/53c26bf9230a1806043b to your computer and use it in GitHub Desktop.
Save ersatzavian/53c26bf9230a1806043b to your computer and use it in GitHub Desktop.
Turn Signal Example Code
http.onrequest(function(req, resp) {
local state = 0;
if ("state" in req.query) {
state = req.query.state.tointeger();
}
if (req.path == "/green") {
device.send("green", state);
} else if (req.path == "/red") {
device.send("red", state);
}
resp.send(200, "OK");
});
agent.on("green", function(state) {
grn.write(state);
});
agent.on("red", function(state) {
red.write(state);
});
red <- hardware.pin2;
grn <- hardware.pinC;
red.configure(DIGITAL_OUT, 0);
grn.configure(DIGITAL_OUT, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment