Skip to content

Commit

Permalink
Regenerate all of the doc/example files
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Dec 2, 2013
1 parent e449678 commit ca469ef
Show file tree
Hide file tree
Showing 87 changed files with 919 additions and 862 deletions.
12 changes: 6 additions & 6 deletions docs/accelerometer-pan-tilt.md
Expand Up @@ -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({
Expand All @@ -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 ?
});
Expand Down
12 changes: 6 additions & 6 deletions docs/accelerometer.md
Expand Up @@ -8,7 +8,7 @@ node eg/accelerometer.js

```javascript
var five = require("johnny-five"),
board, accel;
board, accel;

board = new five.Board();

Expand All @@ -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
});
Expand All @@ -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);
});
});

Expand Down
7 changes: 5 additions & 2 deletions docs/board-multi.md
Expand Up @@ -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)
Expand All @@ -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();
});
});

Expand Down
12 changes: 7 additions & 5 deletions docs/board-with-port.md
Expand Up @@ -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
Expand All @@ -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));
});
});

Expand Down
6 changes: 3 additions & 3 deletions docs/board.md
Expand Up @@ -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));
});
});

Expand Down
67 changes: 38 additions & 29 deletions docs/bug.md
Expand Up @@ -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 = [];
Expand All @@ -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
Expand All @@ -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]
]
};

Expand All @@ -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;
};
Expand All @@ -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;
}

Expand All @@ -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() {
Expand All @@ -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
}
);
};

Expand All @@ -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;
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion docs/button-bumper.md
Expand Up @@ -8,7 +8,7 @@ node eg/button-bumper.js

```javascript
var five = require("johnny-five"),
bumper, led;
bumper, led;

five.Board().on("ready", function() {

Expand Down
2 changes: 1 addition & 1 deletion docs/button-options.md
Expand Up @@ -8,7 +8,7 @@ node eg/button-options.js

```javascript
var five = require("johnny-five"),
board, button;
board, button;

board = new five.Board();

Expand Down
6 changes: 3 additions & 3 deletions docs/button-pullup.md
Expand Up @@ -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() {

Expand All @@ -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();
});

Expand Down
2 changes: 1 addition & 1 deletion docs/button.md
Expand Up @@ -8,7 +8,7 @@ node eg/button.js

```javascript
var five = require("johnny-five"),
board, button;
board, button;

board = new five.Board();

Expand Down

0 comments on commit ca469ef

Please sign in to comment.