Book Image

Raspberry Pi LED Blueprints

By : Agus Kurniawan
Book Image

Raspberry Pi LED Blueprints

By: Agus Kurniawan

Overview of this book

Table of Contents (14 chapters)
Raspberry Pi LED Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Controlling LEDs and lamps using Node.js


In some previous chapters, we learned how to control sensor or actuator devices using Python. In this section, I will show you how to build a program using Node.js to control simple actuator devices, such as LEDs. There are many Node.js libraries, which are able to access Raspberry Pi GPIO. One of these libraries is rpi-gpio. You can find it at https://www.npmjs.com/package/rpi-gpio.

You can install rpi-gpio using the npm command:

$ npm install rpi-gpio

Your Raspberry Pi must be connected to an Internet network because Pi needs to download this module.

Another approach is that you can define your module dependencies on the package.json file. Just write this script into a file named package.json:

{
  "name": "chapter7",
  "version": "0.0.1",
  "dependencies":{
    "rpi-gpio": "latest",
    "async": "latest"

  }
}

After that, you can install Node.js modules from the package.json file by typing the following command:

$ npm install

To use the rpi-gpio library...