Created
November 16, 2014 11:48
-
-
Save mitchellgu/a1ff73e83527437cfcd7 to your computer and use it in GitHub Desktop.
Falangafone Electric Imp Code
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
http.onrequest(function(req, resp) { | |
if (req.path=="/update"){ | |
if ("n" in req.query) { | |
local currentSong = req.query["n"].tointeger(); | |
device.send("led0", currentSong % 2); | |
device.send("led1", currentSong/2 % 2); | |
device.send("led2", currentSong/4 % 2); | |
device.send("led3", currentSong/8 % 2); | |
device.send("led4", currentSong/16 % 2); | |
} | |
} | |
resp.send(200, "OK") | |
}); | |
device.on("button", function(state) { | |
http.get("http://131a46b7.ngrok.com/toggle").sendasync(function(resp) { | |
server.log(resp.statuscode); | |
}); | |
}); |
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
led1 <- hardware.pin1; | |
led1.configure(DIGITAL_OUT, 0); | |
led2 <- hardware.pin2; | |
led2.configure(DIGITAL_OUT, 0); | |
led3 <- hardware.pin5; | |
led3.configure(DIGITAL_OUT, 0); | |
led4 <- hardware.pin7; | |
led4.configure(DIGITAL_OUT, 0); | |
led5 <- hardware.pin8; | |
led5.configure(DIGITAL_OUT, 0); | |
agent.on("led0", function(state) { | |
led1.write(state); | |
}); | |
agent.on("led1", function(state) { | |
led2.write(state); | |
}); | |
agent.on("led2", function(state) { | |
led3.write(state); | |
}); | |
agent.on("led3", function(state) { | |
led4.write(state); | |
}); | |
agent.on("led4", function(state) { | |
led5.write(state); | |
}); | |
btn <- hardware.pin9; | |
btn.configure(DIGITAL_IN_PULLUP, function() { | |
local state = btn.read(); | |
if (state==0) { | |
agent.send("button", state); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment