Instantly share code, notes, and snippets.

@rcoh /therm.nut
Last active Aug 29, 2015

Embed
What would you like to do?
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