Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2012 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4185199 to your computer and use it in GitHub Desktop.
Save anonymous/4185199 to your computer and use it in GitHub Desktop.
Electric Imp code for toggling a porch light (written in squirrel)
server.show("");
// remote porch light toggle
ledState <- 0;
function blink()
{
// Change state
ledState = ledState?0:1;
server.log("ledState val: "+ledState);
// Reflect state to the pin
hardware.pin9.write(ledState);
}
// input class for LED control channel
class inputHTTP extends InputPort
{
name = "power control"
type = "number"
function set(httpVal)
{
server.log("Received val: "+httpVal);
if(httpVal == 1) {
blink();
}
}
}
function watchdog() {
imp.wakeup(60,watchdog);
server.log("watchdog");
}
// start watchdog write every 60 seconds
watchdog();
// Configure pin 9 as an open drain output with internal pull up
hardware.pin9.configure(DIGITAL_OUT_OD_PULLUP);
// Register with the server
imp.configure("Porch light code", [inputHTTP()], []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment