Using .scaleTo() and .fscaleTo() to fine-tune measurements

If you'd like to impose an arbitrary scale on your sensor (say 0100 for percentage), you have some options built into the Johnny-Five API: .scaleTo() and .fscaleTo(). These will scale the raw value from the sensor to match the min and max values you pass in:

sensor.on('change', function(){
// this.value will reflect a scaling from 0-1023 to 0-100 console.log(this.scaleTo([0, 100])); // prints an integer
console.log(this.fscaleTo([0, 100])); // prints a float
})

Now that we know how to handle the data, let's start on our night-light by creating code to print the light-sensor values to the command line. This will also allow us to tweak the change threshold setting and determine what value of the light sensor we should use as an indicator to turn our LED off and on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.96.214