Last active
August 29, 2015 14:03
-
-
Save cat-haines/434e63d6e248081c603d 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
isHacking <- null; | |
message <- ""; | |
device.on("hacking", function(data) { | |
isHacking = data.state; | |
message = format("%s (as of %i) - via an @electricimp agent", (data.state == 0) ? "NOT HACKING" : "HACKING", time()) | |
if (!data.boot) { | |
twitter.tweet(message); | |
} | |
}); |
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
const HTML = @"<html> | |
<head> | |
<title>Hackaday Hacking Indicator</title> | |
</head> | |
<body> | |
<div style='font-size:72px'>%s</div> | |
</body> | |
</html> | |
"; | |
http.onrequest(function(req, resp) { | |
resp.send(200, format(HTML, message)); | |
}); |
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
/******************** Library Code ********************/ | |
API_KEY <- ""; | |
API_SECRET <- ""; | |
AUTH_TOKEN <- ""; | |
TOKEN_SECRET <- ""; | |
class Twitter { ... } | |
/******************** Application Code ********************/ | |
twitter <- Twitter(API_KEY, API_SECRET, AUTH_TOKEN, TOKEN_SECRET); |
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
// configure LED | |
led <- hardware.pin9; | |
led.configure(DIGITAL_OUT) | |
// set and send initial state | |
isHacking <- 0; | |
led.write(isHacking); | |
agent.send("hacking", { state=isHacking, boot=true }); | |
// configure the button | |
button <- hardware.pin1; | |
button.configure(DIGITAL_IN_PULLUP, function() { | |
imp.sleep(0.05); // software debounce | |
local state = button.read(); | |
// button down | |
if (state == 1) { | |
// invert the state | |
isHacking = 1 - isHacking; | |
// set LED, then send to agent | |
led.write(isHacking); | |
agent.send("hacking", {state=isHacking, boot=false }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment