Given at JSConf China. Full notes are here: http://droidsjs.ajf.io
Hardware is becoming more connected and with it is the ability to interact with in in new ways. Principle amongst this is the ability to use JavaScript and NodeJS specifically to be able to talk to hardware such as Arduinos, RaspBerry PIs and other embedded development boards.
This talk discusses the JS Hardware stack and how to interact with it.
13. PROTOTYPES ARE GREAT
var left_motor = new Five.motor({controller: 'I2C'});
var right_motor = new Five.motor({controller: 'PCA34567'});
left_motor.start();
right_motor.stop();
left_motor.prototype.double_speed = function() { .. };
28. HARDWARE HELLO WORLD
var five = require("johnny-five");
if (process.argv[2] == null) {
console.log("You need to supply a device to connect to");
process.exit()
}
var board = five.Board({port: process.argv[2]});
board.on("ready", function() {
var led = new five.Led(10);
led.blink(500);
});
30. WEB PAGE LED
var five = require("johnny-five");
if (process.argv[2] == null) {
console.log("Please supply a device to connect to");
process.exit();
}
// web server elements
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var board;
//
//
// Set up the application server
//
33. MBOT DRIVE CODE
var five = require("johnny-five");
var max_speed_l = 150;
var max_speed_r = 140;
// set up the input
var stdin = process.openStdin();
require('tty').setRawMode(true);
var board = new five.Board({port: process.argv[2]});
var l_motor = r_motor = null;
board.on("ready", function(err) {
if (err){
console.log(err);
return;
}