Created
November 15, 2014 15:54
-
-
Save cat-haines/9b2d2506511e90913330 to your computer and use it in GitHub Desktop.
LED API
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) { | |
| if(req.path=="/led/on") { | |
| device.send("led", 1); | |
| } | |
| if(req.path=="/led/off") { | |
| device.send("led", 0); | |
| } | |
| resp.send(200, "OK") | |
| }); | |
| device.on("button", function(state) { | |
| http.get("http://requestb.in/1gr2jab1").sendasync(function(resp) { | |
| server.log(resp.statuscode); | |
| }); | |
| }); |
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
| led <- hardware.pin9; | |
| led.configure(DIGITAL_OUT, 0); | |
| agent.on("led", function(state) { | |
| led.write(state); | |
| }); | |
| btn <- hardware.pin1; | |
| btn.configure(DIGITAL_IN_PULLUP, function() { | |
| local state = btn.read(); | |
| agent.send("button", state); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment