Handling sensor data in the event handler

When you receive data from a sensor, it will be attached to the JavaScript this object, so when you create a callback for the event handler, do not use the arrow syntax, as you will lose the bindings Johnny-Five places on the this object in JavaScript.

Here's an example of a generic data handler for a change event on a Johnny-Five sensor:

let mySensor = new five.Sensor('PIN_NUMBER')

mySensor.on('change', function() {
console.log(this.value) // logs a value between 0-255 to the console
})

Now that we've established how we'll get the data, let's talk about what the data will look like and how we can manipulate it.

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

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