Transcript
Page 1: JavaScript in the Real World

Javascriptin the

real world

Page 2: JavaScript in the Real World

Andrew Nesbitt

@teabassgithub.com/andrew

Page 3: JavaScript in the Real World

Bertie

@BertramRabbitMr April 2014

Page 4: JavaScript in the Real World
Page 5: JavaScript in the Real World
Page 6: JavaScript in the Real World

Any application that can be written in JavaScript,

will eventually be written in JavaScript

Page 7: JavaScript in the Real World
Page 11: JavaScript in the Real World

reddit.com/r/atwoodslaw

Page 12: JavaScript in the Real World

BuildcatAlex Potsides

Page 13: JavaScript in the Real World

github.com/achingbrain/build-cat

Page 14: JavaScript in the Real World

Hardware hackingwith Javascript

Page 15: JavaScript in the Real World

Why JAvascript?

Page 16: JavaScript in the Real World

Higher Level

Page 17: JavaScript in the Real World

Async

Page 18: JavaScript in the Real World

Lower Barriers

Page 19: JavaScript in the Real World

Javascript is popular871,108 JS repos on github

Page 20: JavaScript in the Real World

Internet of things

Page 21: JavaScript in the Real World

Hardware

Page 22: JavaScript in the Real World

Arduino

Page 23: JavaScript in the Real World

Johnny-fivegithub.com/rwaldron/johnny-five

Page 24: JavaScript in the Real World

Firmata

Page 25: JavaScript in the Real World

var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function() { led = new five.Led({ pin: 9 }); board.repl.inject({ led: led }); led.pulse(500); this.wait( 10000, function() { led.stop().off(); }); });

Page 26: JavaScript in the Real World

Kinect Controlled Arm

Page 27: JavaScript in the Real World

Biped Nodebot

Page 28: JavaScript in the Real World

Cat Laser Toy

Page 29: JavaScript in the Real World

Rabbit Laser Toy

Page 30: JavaScript in the Real World

var five = require("johnny-five"), board = new five.Board(); function randomFromInterval(from,to){ return Math.floor(Math.random()*(to-from+1)+from); } board.on("ready", function() { var servoX = new five.Servo(10); var servoY = new five.Servo(9); var laser = new five.Led(8); laser.on() setInterval(function(){ x = randomFromInterval(80, 120) y = randomFromInterval(95, 145) servoX.move(x) servoY.move(y) }, 400) })

Page 31: JavaScript in the Real World

DEMO

Page 32: JavaScript in the Real World
Page 33: JavaScript in the Real World

github.com/rwaldron/johnny-five

Page 34: JavaScript in the Real World

SparkfunInventors Kithobbytronics.co.uk/sparkfun-inventors-kit-v3

Page 35: JavaScript in the Real World

node-ardx.org

Page 36: JavaScript in the Real World

LEGO

Page 37: JavaScript in the Real World

EV3

Page 38: JavaScript in the Real World
Page 39: JavaScript in the Real World

var Ev3 = require ("ev3-nodejs-bt"); var Ev3_base = Ev3.base; var XboxController = require('xbox-controller'); var xbox = new XboxController; var robot = new Ev3_base("/dev/tty.EV3-SerialPort"); var maxAngle = 32768; var maxSpeed = 100; var speeds = { a: 0, b: 0, c: 0, d: 0 };

Page 40: JavaScript in the Real World

robot.connect(function(){ robot.start_program(function(ev3){ var setSpeed = function(){ var output = ev3.getOutputSequence(speeds.a,speeds.b,speeds.c,speeds.d); ev3.sp.write(output); } setInterval(setSpeed, 100) xbox.on('left:move', function(position){ var x = -(position.x / maxAngle)*-maxSpeed var y = (position.y / maxAngle)*-maxSpeed var left = y-x var right = y+x speeds.b = left speeds.a = right }) xbox.on('a:press', function(){ speeds.d = 100 }) xbox.on('a:release', function(){ speeds.d = 0 }) }); });

Page 41: JavaScript in the Real World

DEMO

Page 42: JavaScript in the Real World
Page 43: JavaScript in the Real World
Page 44: JavaScript in the Real World

github.com/andrew/node-ev3-robot

Page 45: JavaScript in the Real World

github.com/clebert/ev3

Page 46: JavaScript in the Real World

Linux running on lego

Page 47: JavaScript in the Real World

Nodecopter

Page 48: JavaScript in the Real World

Programmatic Flying Robots

Page 49: JavaScript in the Real World

HD Camera

Downfacing camera

Gyroscope

Wifi 1GHz CPU

Linux

Accelerometer Magnetometer

Ultrasound

Page 50: JavaScript in the Real World

github.com/felixge/node-ar-drone

Page 51: JavaScript in the Real World

var arDrone = require('ar-drone'); var client = arDrone.createClient();

client.takeoff();

client .after(5000, function() { this.clockwise(0.5); }) .after(3000, function() { this.animate('flipLeft', 15); }) .after(1000, function() { this.stop(); this.land(); });

Page 52: JavaScript in the Real World

QR CodeR

Page 53: JavaScript in the Real World

Dance Dance Drone

Page 54: JavaScript in the Real World

DEMO

Page 55: JavaScript in the Real World

WARNING

Page 56: JavaScript in the Real World

github.com/eschnou/ardrone-webflight

Page 57: JavaScript in the Real World

Quadcoptersas a

Service

Page 58: JavaScript in the Real World

robot laser pong

Page 59: JavaScript in the Real World

JavaSCript Microcontrollers

Page 60: JavaScript in the Real World
Page 61: JavaScript in the Real World
Page 62: JavaScript in the Real World
Page 63: JavaScript in the Real World

ArduinoYun

Page 64: JavaScript in the Real World

£70 £21 £30 £55

Lua based Tiny-jsNode.js or browser

Node.js

plug and play Hacker friendly Tiny computer Arduino++

Page 65: JavaScript in the Real World

JavaSCript Hardwarein the browser

Page 66: JavaScript in the Real World

In DevelopmentVibration apiAmbient light sensorProximity sensorTCP Socket APIwiki.mozilla.org/WebAPI

Page 67: JavaScript in the Real World

Future?UDP Datagram Socket APIWebNFCWebUSBWebBluetoothwiki.mozilla.org/WebAPI

Page 68: JavaScript in the Real World

whatwg.github.io/serial

Page 69: JavaScript in the Real World

Go forth and make robots

Page 70: JavaScript in the Real World

No animals were harmed in the making of this presentation

Thanks!

Page 71: JavaScript in the Real World

Bonus Content

Page 72: JavaScript in the Real World

Kinect Drone

Page 73: JavaScript in the Real World

NoDebots.io

Page 74: JavaScript in the Real World
Page 75: JavaScript in the Real World
Page 76: JavaScript in the Real World

MakeyMakey

Page 77: JavaScript in the Real World

Rabbit Photo Booth

Page 78: JavaScript in the Real World

<html><body> <video id="v" width="300" height="300" style="display:none;"></video> <canvas id="c" style="display:none;" width="300" height="300"></canvas> <div id='images'></div></body><script> var video = document.getElementById("v"), canvas = document.getElementById("c"), div = document.getElementById('images'); navigator.mozGetUserMedia({video: true}, function(stream) { video.src = window.URL.createObjectURL(stream); video.play() });

takePhoto = function(){ canvas.getContext("2d").drawImage(video, 0, 0, 300, 300); var img = canvas.toDataURL("image/png"); var image = new Image(); image.width = 320 image.height = 240 div.appendChild(image); image.src = img; } window.onkeypress = function(k){ if(k.charCode === 103){ takePhoto() } }</script></html>

Page 79: JavaScript in the Real World

Top Related