Created
April 25, 2015 21:34
-
-
Save ersatzavian/53c26bf9230a1806043b to your computer and use it in GitHub Desktop.
Turn Signal Example Code
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
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"); | |
}); |
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
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