Skip to content

Commit

Permalink
Merge pull request #785 from rwaldron/joystick
Browse files Browse the repository at this point in the history
Joystick: Controller refactor, Esplora support.
  • Loading branch information
rwaldron committed May 19, 2015
2 parents f566d8f + e526cf6 commit 8f0fd12
Show file tree
Hide file tree
Showing 15 changed files with 1,087 additions and 217 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://

### Joystick
- [Joystick](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick.md)
- [Joystick - Claw control](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick-claw.md)
- [Joystick - Esplora](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick-esplora.md)
- [Joystick - Sparkfun Shield](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick-shield.md)
- [Joystick - Pan + Tilt control](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick-pantilt.md)
- [Joystick - Motor control](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick-motor-led.md)

### LCD
- [LCD](https://github.com/rwaldron/johnny-five/blob/master/docs/lcd.md)
Expand Down
Binary file added docs/breadboard/esplora.fzz
Binary file not shown.
Binary file added docs/breadboard/esplora.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/breadboard/joystick-shield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions docs/joystick-esplora.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!--remove-start-->

# Joystick - Esplora



Run with:
```bash
node eg/joystick-esplora.js
```

<!--remove-end-->

```javascript
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
/*
Be sure to reflash your Esplora with StandardFirmata!
In the Arduino IDE:
Tools > Boards > Arduino Leonard or Arduino Esplora
*/
var joystick = new five.Joystick({
controller: "ESPLORA"
});

joystick.on("change", function() {
console.log("Joystick");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log("--------------------------------------");
});
});

```


## Illustrations / Photos


### Joystick - Esplora


Esplora joystick example.


![docs/breadboard/esplora.png](breadboard/esplora.png)<br>

Fritzing diagram: [docs/breadboard/esplora.fzz](breadboard/esplora.fzz)

&nbsp;





&nbsp;

<!--remove-start-->

## License
Copyright (c) 2012, 2013, 2014 Rick Waldron <waldron.rick@gmail.com>
Licensed under the MIT license.
Copyright (c) 2014, 2015 The Johnny-Five Contributors
Licensed under the MIT license.

<!--remove-end-->
32 changes: 13 additions & 19 deletions docs/joystick-pantilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,38 @@ node eg/joystick-pantilt.js
<!--remove-end-->

```javascript
var five = require("johnny-five"),
board = new five.Board({
debug: true
});
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
var range, pan, tilt, joystick;

range = [0, 170];
var range = [0, 170];

// Servo to control panning
pan = new five.Servo({
var pan = new five.Servo({
pin: 9,
range: range
range: range,
center: true
});

// Servo to control tilt
tilt = new five.Servo({
var tilt = new five.Servo({
pin: 10,
range: range
range: range,
center: true
});

// Joystick to control pan/tilt
// Read Analog 0, 1
// Limit events to every 50ms
joystick = new five.Joystick({
var joystick = new five.Joystick({
pins: ["A0", "A1"],
freq: 100
});

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

joystick.on("axismove", function() {

tilt.to(Math.ceil(170 * this.fixed.y));
pan.to(Math.ceil(170 * this.fixed.x));

joystick.on("change", function() {
tilt.to(five.Fn.scale(this.y, -1, 1, 0, 170));
pan.to(five.Fn.scale(this.x, -1, 1, 0, 170));
});
});

Expand Down
62 changes: 62 additions & 0 deletions docs/joystick-shield.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--remove-start-->

# Joystick - Sparkfun Shield



Run with:
```bash
node eg/joystick-shield.js
```

<!--remove-end-->

```javascript
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
var joystick = new five.Joystick({
pins: ["A0", "A1"],
invertY: true
});

joystick.on("change", function() {
console.log("Joystick");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log("--------------------------------------");
});
});

```


## Illustrations / Photos


### Joystick - Sparkfun Shield


Sparkfun Joystick Shield example.


![docs/breadboard/joystick-shield.png](breadboard/joystick-shield.png)<br>

&nbsp;





&nbsp;

<!--remove-start-->

## License
Copyright (c) 2012, 2013, 2014 Rick Waldron <waldron.rick@gmail.com>
Licensed under the MIT license.
Copyright (c) 2014, 2015 The Johnny-Five Contributors
Licensed under the MIT license.

<!--remove-end-->
39 changes: 6 additions & 33 deletions docs/joystick.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,18 @@ board.on("ready", function() {

// Create a new `joystick` hardware instance.
var joystick = new five.Joystick({
// Joystick pins are an array of pins
// Pin orders:
// [ up, down, left, right ]
// [ ud, lr ]
// [ x, y ]
pins: ["A0", "A1"]
});

// Joystick Event API
joystick.on("axismove", function(err, timestamp) {

// Axis data is available on:
// this.axis
// {
// x: 0...1, ( 0 <-- L/R --> 1 )
// y: 0...1 ( 0 <-- D/U --> 1 )
// }
//
// Center is ~0.5
//
// console.log( "input", this.axis );
// console.log( "LR:", this.axis.x, this.normalized.x );
// console.log( "UD:", this.axis.y, this.normalized.y );
// console.log( "MAG:", this.magnitude );

console.log("LR:", this.fixed.x);
console.log("UD:", this.fixed.y);
console.log("MAG:", this.magnitude);

joystick.on("change", function() {
console.log("Joystick");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log("--------------------------------------");
});
});


// Schematic
// https://1965269182786388413-a-1802744773732722657-s-sites.googlegroups.com/site/parallaxinretailstores/home/2-axis-joystick/Joystick-6.png
// http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/27800-Axis%20JoyStick_B%20Schematic.pdf

// Further Reading
// http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/27800-2-AxisJoystick-v1.2.pdf

```


Expand Down
22 changes: 22 additions & 0 deletions eg/joystick-esplora.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();

board.on("ready", function() {
/*
Be sure to reflash your Esplora with StandardFirmata!
In the Arduino IDE:
Tools > Boards > Arduino Leonard or Arduino Esplora
*/
var joystick = new five.Joystick({
controller: "ESPLORA"
});

joystick.on("change", function() {
console.log("Joystick");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log("--------------------------------------");
});
});
32 changes: 13 additions & 19 deletions eg/joystick-pantilt.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
var five = require("../lib/johnny-five.js"),
board = new five.Board({
debug: true
});
var five = require("../lib/johnny-five.js");
var board = new five.Board();

board.on("ready", function() {
var range, pan, tilt, joystick;

range = [0, 170];
var range = [0, 170];

// Servo to control panning
pan = new five.Servo({
var pan = new five.Servo({
pin: 9,
range: range
range: range,
center: true
});

// Servo to control tilt
tilt = new five.Servo({
var tilt = new five.Servo({
pin: 10,
range: range
range: range,
center: true
});

// Joystick to control pan/tilt
// Read Analog 0, 1
// Limit events to every 50ms
joystick = new five.Joystick({
var joystick = new five.Joystick({
pins: ["A0", "A1"],
freq: 100
});

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

joystick.on("axismove", function() {

tilt.to(Math.ceil(170 * this.fixed.y));
pan.to(Math.ceil(170 * this.fixed.x));

joystick.on("change", function() {
tilt.to(five.Fn.scale(this.y, -1, 1, 0, 170));
pan.to(five.Fn.scale(this.x, -1, 1, 0, 170));
});
});
16 changes: 16 additions & 0 deletions eg/joystick-shield.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();

board.on("ready", function() {
var joystick = new five.Joystick({
pins: ["A0", "A1"],
invertY: true
});

joystick.on("change", function() {
console.log("Joystick");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log("--------------------------------------");
});
});
39 changes: 6 additions & 33 deletions eg/joystick.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,14 @@ board.on("ready", function() {

// Create a new `joystick` hardware instance.
var joystick = new five.Joystick({
// Joystick pins are an array of pins
// Pin orders:
// [ up, down, left, right ]
// [ ud, lr ]
// [ x, y ]
pins: ["A0", "A1"]
});

// Joystick Event API
joystick.on("axismove", function(err, timestamp) {

// Axis data is available on:
// this.axis
// {
// x: 0...1, ( 0 <-- L/R --> 1 )
// y: 0...1 ( 0 <-- D/U --> 1 )
// }
//
// Center is ~0.5
//
// console.log( "input", this.axis );
// console.log( "LR:", this.axis.x, this.normalized.x );
// console.log( "UD:", this.axis.y, this.normalized.y );
// console.log( "MAG:", this.magnitude );

console.log("LR:", this.fixed.x);
console.log("UD:", this.fixed.y);
console.log("MAG:", this.magnitude);

joystick.on("change", function() {
console.log("Joystick");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log("--------------------------------------");
});
});


// Schematic
// https://1965269182786388413-a-1802744773732722657-s-sites.googlegroups.com/site/parallaxinretailstores/home/2-axis-joystick/Joystick-6.png
// http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/27800-Axis%20JoyStick_B%20Schematic.pdf

// Further Reading
// http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/27800-2-AxisJoystick-v1.2.pdf
Loading

0 comments on commit 8f0fd12

Please sign in to comment.