Reader small image

You're reading from  Learning JavaScript Robotics

Product typeBook
Published inNov 2015
Reading LevelIntermediate
Publisher
ISBN-139781785883347
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Kassandra Perch
Kassandra Perch
author image
Kassandra Perch

Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them.
Read more about Kassandra Perch

Right arrow

How a Johnny-Five program works


In this section, we'll take a look at the internals of a Johnny-Five program in more detail, so we can start building more complex applications.

Objects, functions, and events

Johnny-Five programs work using an event-based structure, and there are three concepts to keep in mind: objects, functions, and events.

Objects tend to programmatically represent our physical electronic components and are usually constructed using the new keyword. A few examples of objects in Johnny-Five include the five object, which represents the Johnny-Five library, the Board object, which represents our microcontroller; and the LED object, which will programmatically represent our LED:

var led = new five.Led(11);

Functions are available for the objects we create and usually represent the actions that our robots can do. For instance, the LED object has an on() and off() function that turns the LED on and off:

led.on();
led.off();
led.blink();
led.stop();

Events are fired on objects and...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning JavaScript Robotics
Published in: Nov 2015Publisher: ISBN-13: 9781785883347

Author (1)

author image
Kassandra Perch

Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them.
Read more about Kassandra Perch