Last active
August 29, 2015 14:01
-
-
Save rwaldron/04f53147dc5f643a7e2f 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
var five = require("../lib/johnny-five.js"); | |
var board = new five.Board(); | |
function toMV(value) { | |
return five.Fn.map(value, 0, 1023, 0, 5000) | 0; | |
} | |
board.on("ready", function() { | |
var relay = new five.Relay(7); | |
var monitor = new five.Sensor("A0"); | |
var isRelayOn = false; | |
monitor.on("data", function() { | |
var isOn = false; | |
if (toMV(this.value) > 3300) { | |
isOn = true; | |
} | |
if (isRelayOn !== isOn) { | |
isRelayOn = isOn; | |
console.log("Relay is %s", isRelayOn ? "on" : "off"); | |
} | |
}); | |
this.repl.inject({ | |
relay: relay | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment