Last active
August 29, 2015 14:00
-
-
Save rcoh/11240791 to your computer and use it in GitHub Desktop.
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
setPoint <- 68; | |
function updateTemp() { | |
// Read the ambient temperature | |
temp <- readTemp(); | |
// If it's below what it should be, turn on the heat. | |
if (temp < setPoint) { | |
heatOn(); | |
} else { | |
// If it's not below, that means it's above. Turn the heat on! | |
heatOff(); | |
} | |
} | |
function mainLoop() { | |
updateTemp(); | |
// in 60 seconds, call mainLoop again | |
imp.wakeup(60, mainLoop); | |
} | |
function readTemp() { | |
return 60; | |
} | |
// heatControlWire lets us control pin1 of the electric imp. | |
heatControlWire <- hardware.pin1; | |
// Configure it so that 1 = 3.3v and 0 = 0v. | |
heatControlWire.configure(DIGITAL_OUT); | |
function heatOn() { | |
// debug message so you know what the imp is doing | |
server.log("heat is on"); | |
heatControlWire.write(1); | |
} | |
function heatOff() { | |
server.log("heat is off"); | |
heatControlWire.write(0); | |
} | |
mainLoop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment