Giter Site home page Giter Site logo

bot-io's Introduction

bot-io

ADC, GPIO, PWM, UARTs, and more on the BeagleBone Black.

Installation

$ npm install bot-io

Features

  • LEDs - Light Emitting Diodes
  • Buttons and Switches
  • ADC - Analog to Digital Conversion
  • GPIO - General Purpose Input Output
  • PWM - Pulse Width Modulation
  • UART - Serial Communication

Usage

LEDs

Let's start off with something simple that doesn't require any hadrware other than the BeagleBone Black itself. The following example will blink onboard user LED0 at a frequency of 1Hz.

var bot = require('bot-io'),
  led0 = new bot.Led(bot.Led.USR0);

led0.once('ready', function () {
  // Blink at 1Hz. Cycle = 1000ms, on for 500ms, off for 500ms.
  led0.blink();
});

The next example blinks all four onboard user LEDs at 100Hz. Every 250ms the blink delays are adjusted. The LEDs will alternate between glowing dimly and brightly.

var bot = require('bot-io'),
  Led = bot.Led,
  leds;

leds = [Led.USR0, Led.USR1, Led.USR2, Led.USR3].map(function (usrledName) {
  return new Led(usrledName);
});

bot.once('ready', leds, function () {
  var blinkLeds = function (delayOn, delayOff) {
    leds.forEach(function (led) {
      led.blink(delayOn, delayOff);
    });
  };

  setInterval(function () {
    // Blink at 100Hz. Cycle = 10ms, on for 1ms, off for 9ms.
    blinkLeds(1, 9);
    setTimeout(function () {
      // Blink at 100Hz. Cycle = 10ms, on for 9ms, off for 1ms.
      blinkLeds(9, 1);
    }, 250);
  }, 500);
});

Buttons

Toggle the state of an LED every time a button is pressed.

var bot = require('bot-io'),
  button = new bot.Button(bot.pins.p9_24),
  led = new bot.Led(bot.pins.p9_26),
  ledState = 0;

button.on('pressed', function () {
  led.value(ledState ^= 1);
});

PWM - Pulse Width Modulation

Fade an LED on and off once per second.

var bot = require('bot-io'),
  led = new bot.Pwm(bot.pins.p9_42);

led.once('ready', function () {
  var period = led.period(),
    duty = 0,
    delta = period / 50;

  (function updateDuty() {
    led.duty(duty);

    duty += delta;

    if (duty < 0 || duty > period) {
      delta = -delta;
      duty += delta;
    }

    setTimeout(updateDuty, 10);
  }());
});

ADC - Analog to Digital Conversion

Determine the ambient light level with an analog ambient light sensor.

var bot = require('bot-io'),
  ain = new bot.Ain(bot.pins.p9_36);

ain.once('ready', function () {
  setInterval(function () {
    console.log('value: ' + ain.value() + ', rawValue: ' + ain.rawValue());
  }, 1000);
});

Documentation

Classes

  • Ain - Analog to Digital Conversion
  • Button - Buttons and Switches
  • Gpio - General Purpose Input Output
  • Led - Light Emitting Diodes
  • Pwm - Pulse Width Modulation
  • Uart - Serial Communication

Objects

Functions

  • once - One Time Listener

Additional Information

Tested with Debian Image 2014-09-03 and Node.js v0.10.25 on the BeagleBone Black rev. A5C.

bot-io's People

Contributors

fivdi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.