Book Image

Internet of Things with Intel Galileo

By : Miguel de Sousa, Ricardo Miguel F de Sousa
Book Image

Internet of Things with Intel Galileo

By: Miguel de Sousa, Ricardo Miguel F de Sousa

Overview of this book

Table of Contents (17 chapters)
Internet of Things with Intel Galileo
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Launching random LED animations


The one thing that we'll want to do while the videos are playing is to play a random LED animation. To do so, we'll create a new file and develop some methods to help us handle those animations.

The idea is to have a method to stop and set the strip off and the other to select a couple of colors and play an animation, switching between those colors randomly.

To control the LED strip, we will use the lib UPM jsupm_lpd8806 and to loop between the strip LEDs, we will need to use the async module, which will provide us with asynchronous loops. Together with the setTimeout method, this will help us keep the process non-blocking.

Firstly, let's start by installing the async module by typing npm install async inside the project folder (chapter7). When it finishes installing, create a new file by typing vi animations.js and paste the following code:

var LPD8806 = require('jsupm_lpd8806').LPD8806;
var async = require('async');

var stripLength = 30;
var ledstrip = new...