Last active
August 29, 2015 14:02
-
-
Save pierceray/828e32be2316ccc64196 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("johnny-five"), | |
board = new five.Board(); | |
five.Led.prototype.greaterThanSize = function(value){ | |
if (value > this.threshold) { | |
this.on(); | |
} else { | |
this.off(); | |
} | |
}; | |
board.on("ready", function() { | |
// Define LED's | |
var led25 = new five.Led(13), | |
led50 = new five.Led(12), | |
led75 = new five.Led(11), | |
led100 = new five.Led(10); | |
led25["threshold"] = 1; | |
led50["threshold"] = 25; | |
led75["threshold"] = 50; | |
led100["threshold"] = 75; | |
// Range of the scale to measure to light up LED's | |
var range = [0, 100]; | |
photoresistor = new five.Sensor({ | |
//pin to listen to | |
pin: "A0", | |
//how often to check for a change in miliseconds (default value is 25 milliseconds) | |
freq: 150 | |
}); | |
this.repl.inject({ | |
led25: led25, | |
led50: led50, | |
led75: led75, | |
led100: led100, | |
pot: photoresistor | |
}); | |
photoresistor.scale(range).on("data", function() { | |
//outputs to screen the values being used from the photoresistor | |
console.log( "analog value: " + this.analog + " Scaled Value: " + Math.floor(this.scaled) ); | |
var scaledData = Math.floor(this.scaled); | |
ledArray = [led25,led50,led75,led100]; | |
for (var i = 0; i < ledArray.length; i++) { | |
ledArray[i].greaterThanSize(scaledData); | |
}; | |
// if (Math.floor(this.scaled) > 1) { | |
// led25.on(); | |
// } else { | |
// led25.off(); | |
// } | |
// if (Math.floor(this.scaled) > 25) { | |
// led50.on(); | |
// } else { | |
// led50.off(); | |
// } | |
// if (Math.floor(this.scaled) > 50) { | |
// led75.on(); | |
// } else { | |
// led75.off(); | |
// } | |
// if (Math.floor(this.scaled) > 75) { | |
// led100.on(); | |
// } else { | |
// led100.off(); | |
// } | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment