Book Image

Learning JavaScript Robotics

By : Kassandra Perch
Book Image

Learning JavaScript Robotics

By: Kassandra Perch

Overview of this book

Table of Contents (16 chapters)
Learning JavaScript Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding events in Johnny-Five


The events in Johnny-Five are a very important concept—this is also a new concept, especially if you are used to low-level language programming. It's very similar to the idea of interrupts, but definitely strays away from the traditional robotics programming paradigm of an event loop. While you can create timers and loops in Johnny-Five, it highly encourages an event-based programming approach, which can need some practice.

Why events?

A question that gets asked a lot is, "Why event-based? Why not loop-based and interrupt-based as in previous methods?".

A lot of this has to do with the way robots work and the way we think about how we program robots. When you think about what you want a robot to do, you're less likely to think "Every X seconds, I want to check for A and start task B..." and you are more likely to think "When Y happens, I want to start event C...".

The event-based system in Johnny-Five works really well with this train of thought by allowing...