Created
December 1, 2012 21:24
-
-
Save anonymous/4185199 to your computer and use it in GitHub Desktop.
Electric Imp code for toggling a porch light (written in squirrel)
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
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