Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 87 lines (49 sloc) 1.433 kb
6b5ab5b Rick Waldron Rebuild all example program markdown files
authored
1 # Accelerometer Pan Tilt
2
3 Run with:
4 ```bash
5 node eg/accelerometer-pan-tilt.js
6 ```
7
8
9 ```javascript
10 var five = require("johnny-five"),
11 board;
12
13 board = new five.Board();
14
15 board.on("ready", function() {
16
17 var range, pan, tilt, accel;
18
19 range = [ 0, 170 ];
20
21 // Servo to control panning
22 pan = new five.Servo({
23 pin: 9,
24 range: range
25 });
26
27 // Servo to control tilt
28 tilt = new five.Servo({
29 pin: 10,
30 range: range
31 });
32
33 // Accelerometer to control pan/tilt
34 accel = new five.Accelerometer({
35 pins: [ "A3", "A4", "A5" ],
36 freq: 250
37 });
38
39 // Center all servos
40 (five.Servos()).center();
41
42 accel.on("acceleration", function( err, timestamp ) {
43 // console.log( "acceleration", this.axis );
44
45 tilt.move( Math.abs( Math.ceil(170 * this.pitch.toFixed(2)) - 180 ) );
46 pan.move( Math.ceil(170 * this.roll.toFixed(2)) );
47
48 // TODO: Math.abs(v - 180) as inversion function ?
49 });
50 });
51
52 ```
53
54 ## Breadboard
55
56
57
58
5e929ce Rick Waldron Example program updates
authored
59
60 ## Devices
61
62
63
64
6b5ab5b Rick Waldron Rebuild all example program markdown files
authored
65 ## Documentation
66
67 _(Nothing yet)_
68
69
70
71
72
73
74
75
76
77 ## Contributing
78 All contributions must adhere to the the [Idiomatic.js Style Guide](https://github.com/rwldrn/idiomatic.js),
79 by maintaining the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).
80
81 ## Release History
82 _(Nothing yet)_
83
84 ## License
85 Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>
86 Licensed under the MIT license.
Something went wrong with that request. Please try again.