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...