How Johnny-Five handles input

So we've gotten a glimpse of the way Johnny-Five uses events via the board ready event. If you've ever programmed with C and Arduino, you may be familiar with the event loop style of program—a loop runs forever and checks the state of the input devices, then responds accordingly. You may also be aware of interrupt-driven programming, where a change in a hardware pin causes the code to jump to a specific function. 

Johnny-Five code is closer to the interrupt style; events drive nearly all Johnny-Five projects. This has several benefits; you can keep your code organized by event type, and make sure each piece of functionality fires only when it needs to, without having to deal with programming your own hardware interrupt routines.

When a Johnny-Five project receives input from a sensor or device, it fires a data event. But what if you only want to run a function when the environment changes? The change event is for you. We'll look more at the exact event types and when they fire in a later section, but for now keep in mind that events are how you'll capture the data of your sensors and input devices.

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

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