Skip to content
Browse files

Regenerate all of the doc/example files

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information...
1 parent e449678 commit ca469ef156c7caccd257959eb63c9f582dd7edf4 @rwaldron committed Dec 2, 2013
Showing with 919 additions and 862 deletions.
  1. +6 −6 docs/accelerometer-pan-tilt.md
  2. +6 −6 docs/accelerometer.md
  3. +5 −2 docs/board-multi.md
  4. +7 −5 docs/board-with-port.md
  5. +3 −3 docs/board.md
  6. +38 −29 docs/bug.md
  7. +1 −1 docs/button-bumper.md
  8. +1 −1 docs/button-options.md
  9. +3 −3 docs/button-pullup.md
  10. +1 −1 docs/button.md
  11. +12 −11 docs/classic-controller.md
  12. +16 −12 docs/claw.md
  13. +7 −7 docs/continuous-clock.md
  14. +2 −2 docs/continuous.md
  15. +97 −88 docs/ed.md
  16. +55 −54 docs/gripper.md
  17. +7 −7 docs/ir-motion.md
  18. +3 −3 docs/ir-proximity.md
  19. +2 −2 docs/ir-reflect.md
  20. +10 −10 docs/joystick-claw.md
  21. +7 −7 docs/joystick-laser.md
  22. +6 −6 docs/joystick-motor-led.md
  23. +6 −6 docs/joystick.md
  24. +1 −1 docs/laser.md
  25. +11 −11 docs/lcd-enumeratechars.md
  26. +9 −7 docs/lcd-runner-20x4.md
  27. +9 −7 docs/lcd-runner.md
  28. +2 −2 docs/lcd.md
  29. +2 −2 docs/led-fade.md
  30. +12 −8 docs/led-matrix.md
  31. +2 −2 docs/led-on-off.md
  32. +2 −2 docs/led-pulse.md
  33. +4 −4 docs/led-rainbow.md
  34. +1 −1 docs/led-rgb.md
  35. +2 −2 docs/led-strobe.md
  36. +55 −55 docs/magnetometer-log.md
  37. +16 −16 docs/magnetometer-north.md
  38. +4 −4 docs/magnetometer.md
  39. +13 −13 docs/motobot.md
  40. +1 −1 docs/motor-directional.md
  41. +6 −6 docs/motor.md
  42. +90 −86 docs/navigator.md
  43. +4 −4 docs/nodeconf-compass.md
  44. +98 −94 docs/nodeconf-navigator.md
  45. +28 −28 docs/nodeconf-radar.md
  46. +5 −5 docs/nodeconf-slider.md
  47. +12 −11 docs/nunchuk.md
  48. +4 −4 docs/photoresistor-servo.md
  49. +2 −2 docs/photoresistor.md
  50. +3 −3 docs/pin-circuit-event.md
  51. +17 −17 docs/pin.md
  52. +6 −6 docs/ping.md
  53. +2 −2 docs/potentiometer.md
  54. +28 −28 docs/radar.md
  55. +2 −2 docs/repl.md
  56. +3 −3 docs/sensor-fsr-servo.md
  57. +13 −13 docs/sensor-fsr.md
  58. +2 −2 docs/sensor-ir-led-receiver.md
  59. +3 −3 docs/sensor-slider.md
  60. +3 −3 docs/sensor-temperature.md
  61. +3 −3 docs/sensor.md
  62. +2 −2 docs/servo-array.md
  63. +4 −4 docs/servo-digital.md
  64. +3 −3 docs/servo-dual.md
  65. +2 −2 docs/servo-options.md
  66. +2 −2 docs/servo-tutorial.md
  67. +1 −1 docs/servo.md
  68. +26 −26 docs/seven-segment.md
  69. +2 −2 docs/shiftregister.md
  70. +5 −5 docs/slider-log.md
  71. +4 −4 docs/slider-pan.md
  72. +4 −4 docs/slider-servo-control.md
  73. +25 −19 docs/sonar-scan.md
  74. +3 −3 docs/sonar.md
  75. +6 −3 docs/stepper-driver.md
  76. +2 −2 docs/stepper-sweep.md
  77. +3 −3 docs/tinkerkit-button.md
  78. +3 −3 docs/tinkerkit-combo.md
  79. +1 −1 docs/tinkerkit-continuous-servo.md
  80. +3 −2 docs/tinkerkit-gyroscope.md
  81. +7 −7 docs/tinkerkit-joystick.md
  82. +1 −1 docs/tinkerkit-linear-pot.md
  83. +1 −1 docs/tinkerkit-rotary.md
  84. +8 −7 docs/tinkerkit-thermistor.md
  85. +1 −1 docs/tinkerkit-tilt.md
  86. +3 −3 docs/tinkerkit-touch.md
  87. +16 −16 docs/whisker.md
View
12 docs/accelerometer-pan-tilt.md
@@ -8,15 +8,15 @@ node eg/accelerometer-pan-tilt.js
```javascript
var five = require("johnny-five"),
- board;
+ board;
board = new five.Board();
board.on("ready", function() {
var range, pan, tilt, accel;
- range = [ 0, 170 ];
+ range = [0, 170];
// Servo to control panning
pan = new five.Servo({
@@ -32,18 +32,18 @@ board.on("ready", function() {
// Accelerometer to control pan/tilt
accel = new five.Accelerometer({
- pins: [ "A3", "A4", "A5" ],
+ pins: ["A3", "A4", "A5"],
freq: 250
});
// Center all servos
(five.Servos()).center();
- accel.on("acceleration", function( err, timestamp ) {
+ accel.on("acceleration", function(err, timestamp) {
// console.log( "acceleration", this.axis );
- tilt.move( Math.abs( Math.ceil(170 * this.pitch.toFixed(2)) - 180 ) );
- pan.move( Math.ceil(170 * this.roll.toFixed(2)) );
+ tilt.move(Math.abs(Math.ceil(170 * this.pitch.toFixed(2)) - 180));
+ pan.move(Math.ceil(170 * this.roll.toFixed(2)));
// TODO: Math.abs(v - 180) as inversion function ?
});
View
12 docs/accelerometer.md
@@ -8,7 +8,7 @@ node eg/accelerometer.js
```javascript
var five = require("johnny-five"),
- board, accel;
+ board, accel;
board = new five.Board();
@@ -25,7 +25,7 @@ board.on("ready", function() {
//
accel = new five.Accelerometer({
- pins: [ "A3", "A4", "A5" ],
+ pins: ["A3", "A4", "A5"],
freq: 100,
threshold: 0.2
});
@@ -37,18 +37,18 @@ board.on("ready", function() {
// Fires once every N ms, equal to value of freg
// Defaults to 500ms
//
- accel.on("acceleration", function( err, data ) {
+ accel.on("acceleration", function(err, data) {
- console.log( "acceleration", data.smooth );
+ console.log("acceleration", data.smooth);
});
// "axischange"
//
// Fires only when X, Y or Z has changed
//
- accel.on("axischange", function( err, timestamp ) {
+ accel.on("axischange", function(err, timestamp) {
- console.log( "axischange", this.raw );
+ console.log("axischange", this.raw);
});
});
View
7 docs/board-multi.md
@@ -10,7 +10,7 @@ node eg/board-multi.js
var five = require("johnny-five");
// Create 2 board instances with IDs "A" & "B"
-new five.Boards([ "A", "B" ]).on("ready", function() {
+new five.Boards(["A", "B"]).on("ready", function() {
// Both "A" and "B" are initialized
// (connected and available for communication)
@@ -21,7 +21,10 @@ new five.Boards([ "A", "B" ]).on("ready", function() {
// Initialize an Led instance on pin 13 of
// each initialized board and strobe it.
- new five.Led({ pin: 13, board: board }).strobe();
+ new five.Led({
+ pin: 13,
+ board: board
+ }).strobe();
});
});
View
12 docs/board-with-port.md
@@ -8,20 +8,22 @@ node eg/board-with-port.js
```javascript
var five = require("johnny-five"),
- board;
+ board;
// Johnny-Five will try its hardest to detect the port for you,
// however you may also explicitly specify the port by passing
// it as an optional property to the Board constructor:
-board = new five.Board({ port: "/dev/cu.usbmodem411" });
+board = new five.Board({
+ port: "/dev/cu.usbmodem411"
+});
// The board's pins will not be accessible until
// the board has reported that it is ready
board.on("ready", function() {
var val = 0;
// Set pin 13 to OUTPUT mode
- this.pinMode( 13, 1 );
+ this.pinMode(13, 1);
// Mode Table
// INPUT: 0
@@ -31,8 +33,8 @@ board.on("ready", function() {
// SERVO: 4
// Create a loop to "flash/blink/strobe" an led
- this.loop( 50, function() {
- this.digitalWrite( 13, (val = val ? 0 : 1) );
+ this.loop(50, function() {
+ this.digitalWrite(13, (val = val ? 0 : 1));
});
});
View
6 docs/board.md
@@ -15,11 +15,11 @@ five.Board().on("ready", function() {
var val = 0;
// Set pin 13 to OUTPUT mode
- this.pinMode( 13, 1 );
+ this.pinMode(13, 1);
// Create a loop to "flash/blink/strobe" an led
- this.loop( 100, function() {
- this.digitalWrite( 13, (val = val ? 0 : 1) );
+ this.loop(100, function() {
+ this.digitalWrite(13, (val = val ? 0 : 1));
});
});
View
67 docs/bug.md
@@ -9,13 +9,13 @@ node eg/bug.js
```javascript
var five = require("johnny-five");
-function Bug( servos ) {
+function Bug(servos) {
var part, k;
this.isMoving = false;
// Initialize list of body parts
- this.parts = [ "front", "left", "right", "rear" ];
+ this.parts = ["front", "left", "right", "rear"];
// Servo positions
this.history = [];
@@ -28,10 +28,10 @@ function Bug( servos ) {
k = -1;
// Initialize Servo properties from "servos" argument
- while ( ++k < this.parts.length ) {
- part = this.parts[ k ];
+ while (++k < this.parts.length) {
+ part = this.parts[k];
- this[ part ] = servos[ part ] || null;
+ this[part] = servos[part] || null;
}
// Unwind and wait ~10ms, center servos
@@ -43,12 +43,12 @@ function Bug( servos ) {
Bug.STEP_MAP = {
// steps
fwd: [
- [ 10, -30 ],
- [ -15, 30 ]
+ [10, -30],
+ [-15, 30]
],
rev: [
- [ -15, 30 ],
- [ 15, -30 ]
+ [-15, 30],
+ [15, -30]
]
};
@@ -60,13 +60,13 @@ Bug.prototype.idle = function() {
// If the bug is actually in motion,
// stop the servo intervals
- if ( this.isMoving ) {
+ if (this.isMoving) {
this.stop();
}
// set to center position°
- this.front.move( 90 );
- this.rear.move( 90 );
+ this.front.move(90);
+ this.rear.move(90);
//return this;
};
@@ -79,22 +79,23 @@ Bug.prototype.idle = function() {
* dir {String}
* @return {Bug}
*/
-Bug.prototype.step = function( opts ) {
+Bug.prototype.step = function(opts) {
var dir, move, last, front, rear, step;
opts = opts || {};
// Get last move from history if any history exists
// Provide a "fake" history if needed (first call)
last = this.history.length ?
- this.history[ this.history.length - 1 ] :
- { step: 1 };
+ this.history[this.history.length - 1] : {
+ step: 1
+ };
// increment the last step
step = last.step + 1;
// If step is too high, step back to 0
- if ( step > 1 ) {
+ if (step > 1) {
step = 0;
}
@@ -103,20 +104,20 @@ Bug.prototype.step = function( opts ) {
dir = opts.dir || "fwd";
// Derive position° for next move
- move = Bug.STEP_MAP[ dir ][ step ];
+ move = Bug.STEP_MAP[dir][step];
// Assign position° from center
front = 90 + move[0];
rear = 90 + move[1];
// Write position° to servos
- this.front.move( front );
- this.rear.move( rear );
+ this.front.move(front);
+ this.rear.move(rear);
// Allow half step or full if provided,
// defaults to full
// enum(false|null|undefined)
- if ( !opts.half ) {
+ if (!opts.half) {
// Wait one second and move servos back to
// center idling position, 90°
setTimeout(function() {
@@ -129,7 +130,12 @@ Bug.prototype.step = function( opts ) {
this.history.push(
// NOTE: this is a great use case example for
// ES.next concise object initializers
- { dir: dir, step: step, front: front, rear: rear }
+ {
+ dir: dir,
+ step: step,
+ front: front,
+ rear: rear
+ }
);
};
@@ -138,9 +144,9 @@ Bug.prototype.step = function( opts ) {
* @return {Bug}
*/
Bug.prototype.stop = function() {
- Object.keys( this.intervals ).forEach(function( key ) {
- if ( this.intervals[ key ] ) {
- clearInterval( this.intervals[ key ] );
+ Object.keys(this.intervals).forEach(function(key) {
+ if (this.intervals[key]) {
+ clearInterval(this.intervals[key]);
}
}, this);
//return this;
@@ -159,15 +165,18 @@ Bug.prototype.stop = function() {
*/
"rev"
-].forEach(function( dir, k ) {
+].forEach(function(dir, k) {
- Bug.prototype[ dir ] = function() {
+ Bug.prototype[dir] = function() {
this.isMoving = true;
- this.intervals[ dir ] = setInterval(function() {
- this.step({ dir: dir, half: true });
- }.bind(this), 750 );
+ this.intervals[dir] = setInterval(function() {
+ this.step({
+ dir: dir,
+ half: true
+ });
+ }.bind(this), 750);
// //return this;
};
View
2 docs/button-bumper.md
@@ -8,7 +8,7 @@ node eg/button-bumper.js
```javascript
var five = require("johnny-five"),
- bumper, led;
+ bumper, led;
five.Board().on("ready", function() {
View
2 docs/button-options.md
@@ -8,7 +8,7 @@ node eg/button-options.js
```javascript
var five = require("johnny-five"),
- board, button;
+ board, button;
board = new five.Board();
View
6 docs/button-pullup.md
@@ -20,7 +20,7 @@ node eg/button-pullup.js
// https://learn.sparkfun.com/tutorials/pull-up-resistors
var five = require("../lib/johnny-five"),
- button, led;
+ button, led;
five.Board().on("ready", function() {
@@ -31,11 +31,11 @@ five.Board().on("ready", function() {
led = new five.Led(13);
- button.on("down", function(value){
+ button.on("down", function(value) {
led.on();
});
- button.on("up", function(){
+ button.on("up", function() {
led.off();
});
View
2 docs/button.md
@@ -8,7 +8,7 @@ node eg/button.js
```javascript
var five = require("johnny-five"),
- board, button;
+ board, button;
board = new five.Board();
View
23 docs/classic-controller.md
@@ -8,7 +8,7 @@ node eg/classic-controller.js
```javascript
var five = require("johnny-five"),
- board, nunchuk;
+ board, nunchuk;
board = new five.Board();
@@ -47,18 +47,18 @@ board.on("ready", function() {
// Fired when the joystick detects a change in
// axis position.
//
- nunchuk.joystick.left.on( "change", function( err, event ) {
+ nunchuk.joystick.left.on("change", function(err, event) {
console.log(
"Left joystick " + event.axis,
- event.target[ event.axis ],
+ event.target[event.axis],
event.axis, event.direction
);
});
- nunchuk.joystick.right.on( "change", function( err, event ) {
+ nunchuk.joystick.right.on("change", function(err, event) {
console.log(
"Right joystick " + event.axis,
- event.target[ event.axis ],
+ event.target[event.axis],
event.axis, event.direction
);
});
@@ -85,13 +85,14 @@ board.on("ready", function() {
//
- [ "down", "up", "hold" ].forEach(function( type ) {
+ ["down", "up", "hold"].forEach(function(type) {
- nunchuk.on( type, function( err, event ) {
+ nunchuk.on(type, function(err, event) {
console.log(
event.target.which + " is " + type,
- { isUp: event.target.isUp,
+ {
+ isUp: event.target.isUp,
isDown: event.target.isDown
}
);
@@ -100,9 +101,9 @@ board.on("ready", function() {
});
-// Further reading
-// http://media.pragprog.com/titles/msard/tinker.pdf
-// http://lizarum.com/assignments/physical_computing/2008/wii_nunchuck.html
+ // Further reading
+ // http://media.pragprog.com/titles/msard/tinker.pdf
+ // http://lizarum.com/assignments/physical_computing/2008/wii_nunchuck.html
});
```
View
28 docs/claw.md
@@ -8,36 +8,40 @@ node eg/claw.js
```javascript
var five = require("johnny-five"),
- board;
+ board;
board = new five.Board();
board.on("ready", function() {
- var claw = new five.Servo({ pin: 9 }),
- arm = five.Servo({ pin: 10 }),
- degrees = 10,
- incrementer = 10,
- last;
+ var claw = new five.Servo({
+ pin: 9
+ }),
+ arm = five.Servo({
+ pin: 10
+ }),
+ degrees = 10,
+ incrementer = 10,
+ last;
- this.loop( 25, function() {
+ this.loop(25, function() {
- if ( degrees >= 180 || degrees === 0 ) {
+ if (degrees >= 180 || degrees === 0) {
incrementer *= -1;
}
degrees += incrementer;
- if ( degrees === 180 ) {
- if ( !last || last === 90 ) {
+ if (degrees === 180) {
+ if (!last || last === 90) {
last = 180;
} else {
last = 90;
}
- arm.move( last );
+ arm.move(last);
}
- claw.move( degrees );
+ claw.move(degrees);
});
});
View
14 docs/continuous-clock.md
@@ -8,19 +8,19 @@ node eg/continuous-clock.js
```javascript
var five = require("johnny-five"),
- board, servo;
+ board, servo;
board = new five.Board();
board.on("ready", function() {
[
- [ 91, "ccw" ],
- [ 89, "cw" ]
+ [91, "ccw"],
+ [89, "cw"]
- ].forEach(function( def ) {
- five.Servo.prototype[ def[1] ] = function() {
- this.move( def[0] );
+ ].forEach(function(def) {
+ five.Servo.prototype[def[1]] = function() {
+ this.move(def[0]);
};
});
@@ -46,7 +46,7 @@ board.on("ready", function() {
// move( speed )
// Set the speed at which the continuous rotation
// servo will rotate at.
- servo.move( 90 );
+ servo.move(90);
});
View
4 docs/continuous.md
@@ -8,7 +8,7 @@ node eg/continuous.js
```javascript
var five = require("johnny-five"),
- board, servo;
+ board, servo;
board = new five.Board();
@@ -35,7 +35,7 @@ board.on("ready", function() {
// move( speed )
// Set the speed at which the continuous rotation
// servo will rotate at.
- servo.move( 90 );
+ servo.move(90);
});
View
185 docs/ed.md
@@ -8,10 +8,10 @@ node eg/ed.js
```javascript
var five = require("johnny-five"),
- compulsive = require("compulsive");
+ compulsive = require("compulsive");
var ED,
- priv = new WeakMap();
+ priv = new WeakMap();
/**
@@ -33,7 +33,8 @@ var ED,
*
* @param {Object} opts Optional properties object
*/
-function ED( opts ) {
+
+function ED(opts) {
opts = opts || {};
@@ -64,12 +65,12 @@ function ED( opts ) {
// TODO: Support pre-initialized servo instances
this.servos = {
right: {
- hip: opts.right.hip && new five.Servo( opts.right.hip ),
- foot: opts.right.foot && new five.Servo( opts.right.foot )
+ hip: opts.right.hip && new five.Servo(opts.right.hip),
+ foot: opts.right.foot && new five.Servo(opts.right.foot)
},
left: {
- hip: opts.left.hip && new five.Servo( opts.left.hip ),
- foot: opts.left.foot && new five.Servo( opts.left.foot )
+ hip: opts.left.hip && new five.Servo(opts.left.hip),
+ foot: opts.left.foot && new five.Servo(opts.left.foot)
}
};
@@ -82,37 +83,37 @@ function ED( opts ) {
// .left { .foot, .hip }
// .right { .foot, .hip }
//
- [ "right", "left" ].forEach(function( key ) {
+ ["right", "left"].forEach(function(key) {
var descriptor = {};
- [ "foot", "hip" ].forEach(function( part ) {
- descriptor[ part ] = {
+ ["foot", "hip"].forEach(function(part) {
+ descriptor[part] = {
get: function() {
- var history = this.servos[ key ][ part ].history,
- last = history[ history.length - 1 ];
+ var history = this.servos[key][part].history,
+ last = history[history.length - 1];
return last && last.degrees || 90;
}.bind(this)
};
}, this);
- this.degrees[ key ] = {};
+ this.degrees[key] = {};
// And finally, create properties with the generated descriptor
- Object.defineProperties( this.degrees[ key ], descriptor );
- }, this );
+ Object.defineProperties(this.degrees[key], descriptor);
+ }, this);
- Object.defineProperty( this, "isCentered", {
+ Object.defineProperty(this, "isCentered", {
get: function() {
var right, left;
right = this.degrees.right;
left = this.degrees.left;
- if ( (right.foot === 90 && right.hip === 90) &&
- (left.foot === 90 && left.foot === 90) ) {
+ if ((right.foot === 90 && right.hip === 90) &&
+ (left.foot === 90 && left.foot === 90)) {
return true;
}
return false;
@@ -124,12 +125,18 @@ function ED( opts ) {
this.history = [{
timestamp: Date.now(),
side: "right",
- right: { hip: 0, foot: 0 },
- left: { hip: 0, foot: 0 }
+ right: {
+ hip: 0,
+ foot: 0
+ },
+ left: {
+ hip: 0,
+ foot: 0
+ }
}];
// Create an entry in the private data store.
- priv.set( this, {
+ priv.set(this, {
// `isWalking` is used in:
// ED.prototype.(attn|stop)
// ED.prototype.(forward|fwd;reverse|rev)
@@ -145,17 +152,17 @@ function ED( opts ) {
* @return {Object} this
*/
//ED.prototype.attn = ED.prototype.stop = function() {
-ED.prototype.attn = function( options ) {
+ED.prototype.attn = function(options) {
options = options || {};
- if ( !options.isWalking ) {
+ if (!options.isWalking) {
- if ( this.sequence ) {
+ if (this.sequence) {
this.sequence.stop();
this.sequence = null;
}
- priv.set( this, {
+ priv.set(this, {
isWalking: false
});
}
@@ -180,21 +187,20 @@ ED.prototype.attn = function( options ) {
* one of: (fwd, rev, left, right)
*
*/
-ED.prototype.step = function( direct ) {
+ED.prototype.step = function(direct) {
var isLeft, isFwd, opposing, direction, state;
state = priv.get(this);
- if ( /fwd|rev/.test(direct) ) {
+ if (/fwd|rev/.test(direct)) {
direction = direct;
direct = undefined;
- }
- else {
+ } else {
direction = "fwd";
}
// Derive which side to step on; based on last step or explicit step
- this.side = direct || ( this.side !== "right" ? "right" : "left" );
+ this.side = direct || (this.side !== "right" ? "right" : "left");
// Update the value of the current direction
this.direction = direction;
@@ -227,15 +233,15 @@ ED.prototype.step = function( direct ) {
// Lift the currently stepping foot, while
// leaning on the currently opposing foot.
- instruct[ stepping ] = {
+ instruct[stepping] = {
foot: isLeft ? 40 : 140
};
- instruct[ opposing ] = {
+ instruct[opposing] = {
foot: isLeft ? 70 : 110
};
// Swing currently stepping hips
- this.move( instruct );
+ this.move(instruct);
}.bind(this)
},
@@ -244,8 +250,8 @@ ED.prototype.step = function( direct ) {
wait: 500,
task: function() {
var degrees = isLeft ?
- ( isFwd ? 120 : 60 ) :
- ( isFwd ? 60 : 120 );
+ (isFwd ? 120 : 60) :
+ (isFwd ? 60 : 120);
// Swing currently stepping hips
this.move({
@@ -298,23 +304,23 @@ ED.prototype.step = function( direct ) {
abbr: "rev"
}
-].forEach(function( dir ) {
+].forEach(function(dir) {
- ED.prototype[ dir.name ] = ED.prototype[ dir.abbr ] = function() {
+ ED.prototype[dir.name] = ED.prototype[dir.abbr] = function() {
var startAt, stepper, state;
startAt = 10;
state = priv.get(this);
// If ED is already walking in this direction, return immediately;
// This prevents multiple movement loops from being scheduled.
- if ( this.direction === dir.abbr && state.isWalking ) {
+ if (this.direction === dir.abbr && state.isWalking) {
return;
}
// If a sequence reference exists, kill it. This will
// clear all pending queue repeaters.
- if ( this.sequence ) {
+ if (this.sequence) {
this.sequence.stop();
this.sequence = null;
}
@@ -334,39 +340,38 @@ ED.prototype.step = function( direct ) {
isWalking: true
});
- stepper = function( loop ) {
+ stepper = function(loop) {
// Capture of sequence queue reference
- if ( this.sequence === null ) {
+ if (this.sequence === null) {
this.sequence = loop;
}
- this.step( dir.abbr );
+ this.step(dir.abbr);
- if ( !priv.get(this).isWalking ) {
+ if (!priv.get(this).isWalking) {
loop.stop();
}
}.bind(this);
// If the bot is not centered, ie. all servos at 90degrees,
// bring the bot to attention before proceeding.
- if ( !this.isCentered ) {
- this.attn({ isWalking: true });
+ if (!this.isCentered) {
+ this.attn({
+ isWalking: true
+ });
// Offset the amount ms required for attn() to complete
startAt = 750;
}
- this.queue([
- {
- wait: startAt,
- task: function() {
- this.step( dir.abbr );
- }.bind(this)
- },
- {
- loop: 1500,
- task: stepper
- }
- ]);
+ this.queue([{
+ wait: startAt,
+ task: function() {
+ this.step(dir.abbr);
+ }.bind(this)
+ }, {
+ loop: 1500,
+ task: stepper
+ }]);
};
});
@@ -382,7 +387,7 @@ ED.prototype.dance = function() {
this.attn();
- if ( typeof this.moves === "undefined" ) {
+ if (typeof this.moves === "undefined") {
this.moves = 0;
}
@@ -393,7 +398,7 @@ ED.prototype.dance = function() {
task: function() {
var degrees = isLeft ? 120 : 60;
- if ( this.moves % 2 === 0 ) {
+ if (this.moves % 2 === 0) {
this.move({
type: "attn",
right: {
@@ -491,77 +496,79 @@ ED.prototype.dance = function() {
* @param {Object} positions left/right hip/foot positions
*
*/
-ED.prototype.move = function( positions ) {
+ED.prototype.move = function(positions) {
var start, type;
- if ( this.history.length ) {
- start = this.history[ this.history.length - 1 ];
+ if (this.history.length) {
+ start = this.history[this.history.length - 1];
}
type = positions.type || "step";
- [ "foot", "hip" ].forEach(function( section ) {
- [ "right", "left" ].forEach(function( side ) {
+ ["foot", "hip"].forEach(function(section) {
+ ["right", "left"].forEach(function(side) {
var interval, endAt, startAt, servo, step, s;
- if ( typeof positions[ side ] === "undefined" ) {
+ if (typeof positions[side] === "undefined") {
return;
}
- endAt = positions[ side ][ section ];
- servo = this.servos[ side ][ section ];
- startAt = this.degrees[ side ][ section ];
+ endAt = positions[side][section];
+ servo = this.servos[side][section];
+ startAt = this.degrees[side][section];
// Degrees per step
step = 2;
s = Date.now();
- if ( !endAt || endAt === startAt ) {
+ if (!endAt || endAt === startAt) {
return;
}
- if ( start ) {
+ if (start) {
// Determine degree step direction
- if ( endAt < startAt ) {
+ if (endAt < startAt) {
step *= -1;
}
// Repeat each step for required number of steps to move
// servo into new position. Each step is ~20ms duration
- this.repeat( Math.abs( endAt - startAt ) / 2, 10, function() {
+ this.repeat(Math.abs(endAt - startAt) / 2, 10, function() {
// console.log( startAt );
- servo.move( startAt += step );
+ servo.move(startAt += step);
- if ( startAt === endAt ) {
- this.times[ type ] = (this.times[ type ] + (Date.now() - s)) / 2;
+ if (startAt === endAt) {
+ this.times[type] = (this.times[type] + (Date.now() - s)) / 2;
}
}.bind(this));
} else {
// TODO: Stop doing this
- servo.move( endAt );
+ servo.move(endAt);
five.Fn.sleep(500);
}
- }, this );
- }, this );
+ }, this);
+ }, this);
// Push a record object into the stepping history
this.history.push({
timestamp: Date.now(),
side: this.side,
- right: five.Fn.extend(
- { hip: 0, foot: 0 }, this.degrees.right, positions.right
- ),
- left: five.Fn.extend(
- { hip: 0, foot: 0 }, this.degrees.left, positions.left
- )
+ right: five.Fn.extend({
+ hip: 0,
+ foot: 0
+ }, this.degrees.right, positions.right),
+ left: five.Fn.extend({
+ hip: 0,
+ foot: 0
+ }, this.degrees.left, positions.left)
});
};
// Borrow API from Compulsive
-[ "wait", "loop", "queue", "repeat" ].forEach(function( api ) {
- ED.prototype[ api ] = compulsive[ api ];
+["wait", "loop", "queue", "repeat"].forEach(function(api) {
+ ED.prototype[api] = compulsive[api];
});
// Begin program when the board, serial and
@@ -573,10 +580,12 @@ ED.prototype.move = function( positions ) {
// assign servos
biped = new ED({
right: {
- hip: 9, foot: 11
+ hip: 9,
+ foot: 11
},
left: {
- hip: 10, foot: 12
+ hip: 10,
+ foot: 12
}
});
View
109 docs/gripper.md
@@ -8,74 +8,75 @@ node eg/gripper.js
```javascript
var five = require("johnny-five"),
- compulsive = require("compulsive"),
- wrist, gripper, motion, repeater;
+ compulsive = require("compulsive"),
+ wrist, gripper, motion, repeater;
(new five.Board()).on("ready", function() {
- // Create a new `gripper` hardware instance.
- // This example allows the gripper module to
- // create a completely default instance
+ // Create a new `gripper` hardware instance.
+ // This example allows the gripper module to
+ // create a completely default instance
- wrist = new five.Servo(9);
- gripper = new five.Gripper(10);
+ wrist = new five.Servo(9);
+ gripper = new five.Gripper(10);
- function slice() {
- wrist.move(100);
+ function slice() {
+ wrist.move(100);
- compulsive.wait(100, function() {
- wrist.move(120);
- });
- }
- function chop() {
- compulsive.loop(200, function( loop ) {
- if ( !repeater ) {
- repeater = loop;
- }
- slice();
+ compulsive.wait(100, function() {
+ wrist.move(120);
+ });
+ }
+
+ function chop() {
+ compulsive.loop(200, function(loop) {
+ if (!repeater) {
+ repeater = loop;
+ }
+ slice();
+ });
+ }
+
+ // Inject the `gripper` hardware into
+ // the Repl instance's context;
+ // allows direct command line access
+ this.repl.inject({
+ w: wrist,
+ g: gripper,
+ chop: chop,
+ slice: slice
});
- }
-
- // Inject the `gripper` hardware into
- // the Repl instance's context;
- // allows direct command line access
- this.repl.inject({
- w: wrist,
- g: gripper,
- chop: chop,
- slice: slice
- });
- motion = new five.IR.Motion(7);
-
- // gripper.open()
- //
- // gripper.close()
- //
- // gripper.set([0-10])
- //
- //
- // g.*() from REPL
- //
- //
- motion.on("motionstart", function( err, ts ) {
- chop();
- });
+ motion = new five.IR.Motion(7);
+
+ // gripper.open()
+ //
+ // gripper.close()
+ //
+ // gripper.set([0-10])
+ //
+ //
+ // g.*() from REPL
+ //
+ //
+ motion.on("motionstart", function(err, ts) {
+ chop();
+ });
- // "motionstart" events are fired following a "motionstart event
- // when no movement has occurred in X ms
- motion.on("motionend", function( err, ts ) {
- if ( repeater ) {
- repeater.stop();
- repeater = null;
- }
- });
+ // "motionstart" events are fired following a "motionstart event
+ // when no movement has occurred in X ms
+ motion.on("motionend", function(err, ts) {
+ if (repeater) {
+ repeater.stop();
+ repeater = null;
+ }
+ });
-});
+ });
```
View
14 docs/ir-motion.md
@@ -8,7 +8,7 @@ node eg/ir-motion.js
```javascript
var five = require("johnny-five"),
- board, motion;
+ board, motion;
board = new five.Board();
@@ -27,20 +27,20 @@ board.on("ready", function() {
// Pir Event API
// "calibrated" occurs once, at the beginning of a session,
- motion.on("calibrated", function( err, ts ) {
- console.log( "calibrated", ts );
+ motion.on("calibrated", function(err, ts) {
+ console.log("calibrated", ts);
});
// "motionstart" events are fired when the "calibrated"
// proximal area is disrupted, generally by some form of movement
- motion.on("motionstart", function( err, ts ) {
- console.log( "motionstart", ts );
+ motion.on("motionstart", function(err, ts) {
+ console.log("motionstart", ts);
});
// "motionstart" events are fired following a "motionstart event
// when no movement has occurred in X ms
- motion.on("motionend", function( err, ts ) {
- console.log( "motionend", ts );
+ motion.on("motionend", function(err, ts) {
+ console.log("motionend", ts);
});
});
View
6 docs/ir-proximity.md
@@ -34,7 +34,7 @@ five.Board().on("ready", function() {
ir.on("motionstart", function() {
- console.log( "motionstart" );
+ console.log("motionstart");
});
@@ -45,15 +45,15 @@ five.Board().on("ready", function() {
ir.on("motionend", function() {
- console.log( "motionend" );
+ console.log("motionend");
});
// "data"
//
// Fires continuously, every 66ms.
//
- ir.on("data", function( err, timestamp ) {
+ ir.on("data", function(err, timestamp) {
// console.log( "data" );
});
});
View
4 docs/ir-reflect.md
@@ -28,8 +28,8 @@ five.Board().on("ready", function() {
//
// Fires continuously, every 66ms.
//
- ir.on("data", function( err, timestamp ) {
- console.log( "data" );
+ ir.on("data", function(err, timestamp) {
+ console.log("data");
});
});
View
20 docs/joystick-claw.md
@@ -8,30 +8,30 @@ node eg/joystick-claw.js
```javascript
var five = require("johnny-five"),
- board, claw, joystick;
+ board, claw, joystick;
board = new five.Board();
board.on("ready", function() {
var claw = new five.Servo({
- pin: 9,
- range: [ 0, 170 ]
- }),
- joystick = new five.Joystick({
- pins: [ "A0", "A1" ],
- freq: 250
- });
+ pin: 9,
+ range: [0, 170]
+ }),
+ joystick = new five.Joystick({
+ pins: ["A0", "A1"],
+ freq: 250
+ });
// Set the claw degrees to half way
// (the joystick deadzone)
- claw.move( 90 );
+ claw.move(90);
joystick.on("axismove", function() {
// Open/close the claw by setting degrees according
// to Y position of joystick.
// limit to 170 on medium servos (ei. the servo used on the claw)
- claw.move( Math.ceil(170 * this.fixed.y) );
+ claw.move(Math.ceil(170 * this.fixed.y));
});
});
View
14 docs/joystick-laser.md
@@ -8,14 +8,14 @@ node eg/joystick-laser.js
```javascript
var five = require("johnny-five"),
- board = new five.Board({
- debug: true
- });
+ board = new five.Board({
+ debug: true
+ });
board.on("ready", function() {
var range, pan, tilt, joystick;
- range = [ 0, 170 ];
+ range = [0, 170];
// Servo to control panning
pan = new five.Servo({
@@ -33,7 +33,7 @@ board.on("ready", function() {
// Read Analog 0, 1
// Limit events to every 50ms
joystick = new five.Joystick({
- pins: [ "A0", "A1" ],
+ pins: ["A0", "A1"],
freq: 100
});
@@ -42,8 +42,8 @@ board.on("ready", function() {
joystick.on("axismove", function() {
- tilt.move( Math.ceil(170 * this.fixed.y) );
- pan.move( Math.ceil(170 * this.fixed.x) );
+ tilt.move(Math.ceil(170 * this.fixed.y));
+ pan.move(Math.ceil(170 * this.fixed.x));
});
});
View
12 docs/joystick-motor-led.md
@@ -8,7 +8,7 @@ node eg/joystick-motor-led.js
```javascript
var five = require("johnny-five"),
- board, joystick, motor, led;
+ board, joystick, motor, led;
board = new five.Board();
@@ -20,7 +20,7 @@ board.on("ready", function() {
// Pin orders:
// [ up, down, left, right ]
// [ ud, lr ]
- pins: [ "A0", "A1" ],
+ pins: ["A0", "A1"],
freq: 25
});
@@ -46,21 +46,21 @@ board.on("ready", function() {
// Pushing the joystick to up position should start the motor,
// releasing it will turn the motor off.
- joystick.on("axismove", function( err, timestamp ) {
+ joystick.on("axismove", function(err, timestamp) {
- if ( !motor.isOn && this.axis.y > 0.51 ) {
+ if (!motor.isOn && this.axis.y > 0.51) {
motor.start();
}
- if ( motor.isOn && this.axis.y < 0.51 ) {
+ if (motor.isOn && this.axis.y < 0.51) {
motor.stop();
}
});
// While the motor is on, blink the led
motor.on("start", function() {
// 250ms
- led.strobe( 250 );
+ led.strobe(250);
});
motor.on("stop", function() {
View
12 docs/joystick.md
@@ -8,7 +8,7 @@ node eg/joystick.js
```javascript
var five = require("johnny-five"),
- board, joystick;
+ board, joystick;
board = new five.Board();
@@ -20,7 +20,7 @@ board.on("ready", function() {
// Pin orders:
// [ up, down, left, right ]
// [ ud, lr ]
- pins: [ "A0", "A1" ],
+ pins: ["A0", "A1"],
freq: 500
});
@@ -33,7 +33,7 @@ board.on("ready", function() {
// Joystick Event API
- joystick.on("axismove", function( err, timestamp ) {
+ joystick.on("axismove", function(err, timestamp) {
// Axis data is available on:
// this.axis
@@ -49,9 +49,9 @@ board.on("ready", function() {
// 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 );
+ console.log("LR:", this.fixed.x);
+ console.log("UD:", this.fixed.y);
+ console.log("MAG:", this.magnitude);
});
});
View
2 docs/laser.md
@@ -8,7 +8,7 @@ node eg/laser.js
```javascript
var five = require("johnny-five"),
- board, laser;
+ board, laser;
board = new five.Board();
View
22 docs/lcd-enumeratechars.md
@@ -8,7 +8,7 @@ node eg/lcd-enumeratechars.js
```javascript
var five = require("../lib/johnny-five"),
- board, lcd;
+ board, lcd;
board = new five.Board();
@@ -17,7 +17,7 @@ board.on("ready", function() {
lcd = new five.LCD({
// LCD pin name RS EN DB4 DB5 DB6 DB7
// Arduino pin # 7 8 9 10 11 12
- pins: [ 7, 8, 9, 10, 11, 12 ],
+ pins: [7, 8, 9, 10, 11, 12],
rows: 4,
cols: 20
});
@@ -32,27 +32,27 @@ board.on("ready", function() {
length = keys.length;
eights = [];
- while ( i < length ) {
- eights.push( keys.slice(i, i + 8) );
+ while (i < length) {
+ eights.push(keys.slice(i, i + 8));
i += 8;
}
- console.log( "Wait 5 seconds..." );
+ console.log("Wait 5 seconds...");
- board.loop( 2000, function() {
- var charset = eights[ k ],
- display = "";
+ board.loop(2000, function() {
+ var charset = eights[k],
+ display = "";
lcd.clear();
- if ( k < eights.length ) {
+ if (k < eights.length) {
- charset.forEach(function( char, index ) {
+ charset.forEach(function(char, index) {
lcd.useChar(char);
display += ":" + char + ":";
});
- lcd.clear().cursor(0, 0).print( display );
+ lcd.clear().cursor(0, 0).print(display);
k++;
}
View
16 docs/lcd-runner-20x4.md
@@ -8,7 +8,7 @@ node eg/lcd-runner-20x4.js
```javascript
var five = require("../lib/johnny-five"),
- board, lcd;
+ board, lcd;
board = new five.Board();
@@ -17,28 +17,30 @@ board.on("ready", function() {
lcd = new five.LCD({
// LCD pin name RS EN DB4 DB5 DB6 DB7
// Arduino pin # 7 8 9 10 11 12
- pins: [ 7, 8, 9, 10, 11, 12 ],
+ pins: [7, 8, 9, 10, 11, 12],
rows: 4,
cols: 20
});
lcd.on("ready", function() {
- var frame = 1, col = 0, row = 0;
+ var frame = 1,
+ col = 0,
+ row = 0;
lcd.useChar("runninga");
lcd.useChar("runningb");
- board.loop( 300, function() {
+ board.loop(300, function() {
- lcd.clear().cursor( row, col ).print(
+ lcd.clear().cursor(row, col).print(
":running" + (++frame % 2 === 0 ? "a" : "b") + ":"
);
- if ( ++col === lcd.cols ) {
+ if (++col === lcd.cols) {
col = 0;
- if ( ++row === lcd.rows ) {
+ if (++row === lcd.rows) {
row = 0;
}
}
View
16 docs/lcd-runner.md
@@ -8,7 +8,7 @@ node eg/lcd-runner.js
```javascript
var five = require("../lib/johnny-five"),
- board, lcd;
+ board, lcd;
board = new five.Board();
@@ -17,28 +17,30 @@ board.on("ready", function() {
lcd = new five.LCD({
// LCD pin name RS EN DB4 DB5 DB6 DB7
// Arduino pin # 7 8 9 10 11 12
- pins: [ 7, 8, 9, 10, 11, 12 ],
+ pins: [7, 8, 9, 10, 11, 12],
rows: 2,
cols: 16
});
lcd.on("ready", function() {
- var frame = 1, col = 0, row = 0;
+ var frame = 1,
+ col = 0,
+ row = 0;
lcd.useChar("runninga");
lcd.useChar("runningb");
- board.loop( 300, function() {
+ board.loop(300, function() {
- lcd.clear().cursor( row, col ).print(
+ lcd.clear().cursor(row, col).print(
":running" + (++frame % 2 === 0 ? "a" : "b") + ":"
);
- if ( ++col === lcd.cols ) {
+ if (++col === lcd.cols) {
col = 0;
- if ( ++row === lcd.rows ) {
+ if (++row === lcd.rows) {
row = 0;
}
}
View
4 docs/lcd.md
@@ -8,7 +8,7 @@ node eg/lcd.js
```javascript
var five = require("../lib/johnny-five"),
- board, lcd;
+ board, lcd;
board = new five.Board();
@@ -17,7 +17,7 @@ board.on("ready", function() {
lcd = new five.LCD({
// LCD pin name RS EN DB4 DB5 DB6 DB7
// Arduino pin # 7 8 9 10 11 12
- pins: [ 7, 8, 9, 10, 11, 12 ],
+ pins: [7, 8, 9, 10, 11, 12],
// Options:
// bitMode: 4 or 8, defaults to 4
View
4 docs/led-fade.md
@@ -8,7 +8,7 @@ node eg/led-fade.js
```javascript
var five = require("johnny-five"),
- board, led;
+ board, led;
board = new five.Board();
@@ -37,7 +37,7 @@ board.on("ready", function() {
// Toggle the led after 10 seconds (shown in ms)
- this.wait( 5000, function() {
+ this.wait(5000, function() {
led.fadeOut();
View
20 docs/led-matrix.md
@@ -8,7 +8,7 @@ node eg/led-matrix.js
```javascript
var five = require("../lib/johnny-five"),
- board, lc;
+ board, lc;
board = new five.Board();
@@ -38,26 +38,30 @@ board.on("ready", function() {
});
function queue(fn) {
- process.nextTick( fn );
+ process.nextTick(fn);
}
lc.heart = function() {
heart.forEach(function(row, rowIndex) {
- queue( function() { lc.row( 0, rowIndex, parseInt( row, 2 ) ); } );
+ queue(function() {
+ lc.row(0, rowIndex, parseInt(row, 2));
+ });
});
};
- lc.on( 0 );
+ lc.on(0);
var msg = "johnny-five";
var idx = 0;
function next() {
- var c = msg[ idx ];
- lc.char( 0, c );
+ var c = msg[idx];
+ lc.char(0, c);
idx++;
- if ( idx === msg.length ) { return; }
- setTimeout( next, 800 );
+ if (idx === msg.length) {
+ return;
+ }
+ setTimeout(next, 800);