Rick Waldron

@rwaldron

github.com/rwldrn




Johnny-Five

JavaScript Arduino Programming

Autopass, C, C++,
Loglisp, Java,
Python, Pascal, RobotC...




Just JavaScript.

Because, like Max said, "JIFSNIF" ;)





Why?




Hardware

Blocking, Synchronous




JavaScript

Streams, Evented, Asynchrononous





Perfect Match.



Firmata

I/O Protocol

by Julian Gaultier



github.com/jgautier/firmata



Serialport

Streaming Bits & Bytes

by Chris Williams



github.com/voodootikigod/node-serialport



Duino

Inspiration

by Cam Pederson (& Me)



github.com/ecto/duino





Johnny-Five



github.com/rwldrn/johnny-five

var five = require("johnny-five");

five.Board().on("ready", function() {
  // "strobe" an led in 100ms on-off phases
  five.Led(13).strobe();
});



Yawn.




Accelerometer, Button, Compass, Led, Joystick, Motor, (Ultrasonic) Ping, Proximity IR, Range IR, Sensor, Servo, Sonar





Joystick Controlled Robot Claw

Joystick + Servo

Arrow Down for Code and Video

var five = require("johnny-five");

five.Board().on("ready", function() {
  var claw, joystick;

  // Claw servo controller
  claw = new five.Servo(9);

  // Joystick controller
  joystick = new five.Joystick({
    // x, y (vertical, horizontal)
    pins: [ "A0", "A1" ]
  });

  // Center the claw servo to match the joystick deadzone.
  claw.center();

  // When the joystick axis are moved...
  joystick.on("axismove", function() {
    // Open & close the claw by setting degrees according
    // to Y position value of joystick.
    claw.move( Math.ceil(180 * this.fixed.y) );
  });
});

12 code lines: 3 boilerplate. 6 setup. 3 program.





Joystick Controlled LASER

Joystick + Servos + LED Laser

Arrow Down for Code and Video

var five = require("johnny-five");

five.Board().on("ready", function() {
  var pan, tilt, joystick;

  // Pan servo
  pan = new five.Servo(9);

  // Tilt servo
  tilt = new five.Servo(10);

  // Joystick controller
  joystick = new five.Joystick({
    pins: [ "A0", "A1" ]
  });

  // Center all servos
  five.Servos().center();

  joystick.on("axismove", function() {
    tilt.move( Math.ceil(180 * this.fixed.y) );
    pan.move( Math.ceil(180 * this.fixed.x) );
  });
});

14 code lines: 3 boilerplate. 7 setup. 4 program.





Show off.





The Compass

var color = require("colors"),
    five = require("../lib/johnny-five.js"),
    colors, mag;

five.Board().on("ready", function() {

  // Create an I2C `Magnetometer` instance
  mag = new five.Magnetometer();

  // As the heading changes, log heading value
  mag.on("headingchange", function() {
    var log;

    log = ( this.bearing.name + " " + Math.floor(this.heading) + "°" );

    console.log(
      log[ colors[ this.bearing.abbr ] ]
    );
  });
});

// `colors` assignment is not shown because it's a big ugly list




The Radar

Arrow Down for Video





The Navigator

Arrow Down for Video