Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Last active August 29, 2015 14:01
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 rwaldron/04f53147dc5f643a7e2f to your computer and use it in GitHub Desktop.
Save rwaldron/04f53147dc5f643a7e2f to your computer and use it in GitHub Desktop.
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