Controlling the IoT world like a wizard

Wizards

You want to be one.

We'll get there.

Eventually.

Can Leap Motion help the IoT world get there?

What is a Leap Motion?

Advantages

Ten fingers and a natural 3D plane of input

Use motions and gestures to control things

Best for a control center style input

Disadvantages

Not so portable yet

Not compatible with Raspberry Pi, only Mac and Windows

A few demos

Using NodeJS and Leap Motion to light Arduino LEDs

The simple bit

var five = require('johnny-five'),
	Leap = require('leapjs'),
	board = new five.Board();

Set up the Leap Motion controller

var controller = new Leap.Controller({
	enableGestures: true
});

Wait till the Arduino board is ready

board.on("ready", function() {
	// Our code will go here.
});

Read in Leap Motion stuff

controller.on("frame", function(frame) {
	if (frame.hands.length > 0) {
		var hand = frame.hands[0],
			sphereCenter = hand.sphereCenter;

		// We'll use hand.sphereCenter here
	}
});

controller.connect();

Shift Register

shiftRegister = new five.ShiftRegister({
	pins: {
		data: datapin,
		clock: clockpin,
		latch: latchpin
	}
});

Detect where we are

if (sphereCenter[0] < -50) {
	if (sphereCenter[2] < 0) {
		shiftRegister.send(0x08);
	} else if (sphereCenter[2] >= 0) {
		shiftRegister.send(0x80);
	}
} else if (sphereCenter[0] > 50) {
	if (sphereCenter[2] < 0) {
		shiftRegister.send(0x01);
	} else if (sphereCenter[2] >= 0) {
		shiftRegister.send(0x10);
	}
} else if (sphereCenter[0] >= -50 && sphereCenter[0] <= 0) {
	if (sphereCenter[2] < 0) {
		shiftRegister.send(0x04);
	} else if (sphereCenter[2] >= 0) {
		shiftRegister.send(0x40);
	}
} else if (sphereCenter[0] > 0 && sphereCenter[0] <= 50) {
	if (sphereCenter[2] < 0) {
		shiftRegister.send(0x02);
	} else if (sphereCenter[2] >= 0) {
		shiftRegister.send(0x20);
	}
}

Just make sure you limit calls!

limitCalls();

function limitCalls() {
	allowLEDchange = true;
	setTimeout(limitCalls, 300);
}

controller.on("frame", function(frame) {
	if (allowLEDchange) {
		allowLEDchange = false;
		// Our throttled code
	}
}

Leap Motion calls

controller.on('ready', function() {
	console.log("ready");
});
controller.on('connect', function() {
	console.log("connect");
});
controller.on('disconnect', function() {
	console.log("disconnect");
});
controller.on('focus', function() {
	console.log("focus");
});
controller.on('blur', function() {
	console.log("blur");
});
controller.on('deviceConnected', function() {
	console.log("deviceConnected");
});
controller.on('deviceDisconnected', function() {
	console.log("deviceDisconnected");
});

What about... controlling my phone?

Let's look at the actual code this time...

(Imagine a pretty control center display here)

If we have time... MIDI sound demo!

And that is all!

Thanks!

Come say hi!

In real life or virtually

http://patcat.me

@thatpatrickguy

/

#