Johnny-Five sensor events

As discussed in the previous chapters, Johnny-Five is dependent on events for a lot of its functionality. This is not different for inputs and sensors—most of the time, you'll interact with these by waiting for events. While most input devices have ways way to read data at any given moment, these are mostly used for debugging, and you'll need to have a good grasp of the events available for your input device or sensor when coding your projects.

Most input devices and sensors have a data event; this event tells the program when data is read from the device. This is a kind of a firehose: it reports quite quickly and can be a little overwhelming. This is usually used for debugging, as most robotics programs are more interested in when the sensor or input data changes rather than when there is new input to be read.

The change event, also available on most devices, is a very commonly-used event—it only fires when the incoming data has changed. A good example is a temperature change as we'll see in one of the projects in this chapter.

The best way to figure out what events to use is by the Johnny-Five documentation for your device at johnny-five.io; this will give you a full list of events for each input and sensor type and can be very helpful when starting new projects.

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

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