Skip to content

Commit bf8a6d4

Browse files
dtexrwaldron
authored andcommitted
Update Stepper examples
1 parent ca68b6e commit bf8a6d4

8 files changed

+142
-50
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
271271

272272
### Stepper Motor
273273
- [Stepper - Driver](https://github.com/rwaldron/johnny-five/blob/master/docs/stepper-driver.md)
274+
- [Stepper - Four Wire](https://github.com/rwaldron/johnny-five/blob/master/docs/stepper-four_wire.md)
274275
- [Stepper - Sweep](https://github.com/rwaldron/johnny-five/blob/master/docs/stepper-sweep.md)
275276

276277
### ESC & Brushless Motor

docs/stepper-driver.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ node eg/stepper-driver.js
2929

3030

3131
```javascript
32-
var five = require("johnny-five");
33-
var board = new five.Board();
32+
const {Board, Stepper} = require("johnny-five");
33+
const board = new Board();
3434

35-
board.on("ready", function() {
35+
board.on("ready", () => {
3636

3737
/**
3838
* In order to use the Stepper class, your board must be flashed with
@@ -43,28 +43,29 @@ board.on("ready", function() {
4343
*
4444
*/
4545

46-
var stepper = new five.Stepper({
47-
type: five.Stepper.TYPE.DRIVER,
46+
const stepper = new Stepper({
47+
type: Stepper.TYPE.DRIVER,
4848
stepsPerRev: 200,
4949
pins: {
5050
step: 12,
5151
dir: 11
5252
}
5353
});
5454

55-
// Make 10 full revolutions counter-clockwise at 180 rpm with acceleration and deceleration
56-
stepper.rpm(180).ccw().accel(1600).decel(1600).step(2000, function() {
55+
// Set stepper to 180 RPM, counter-clockwise with acceleration and deceleration
56+
stepper.rpm(180).ccw().accel(1600).decel(1600);
57+
58+
// Make 10 full revolutions
59+
stepper.step(2000, () => {
5760

5861
console.log("Done moving CCW");
5962

6063
// once first movement is done, make 10 revolutions clockwise at previously
6164
// defined speed, accel, and decel by passing an object into stepper.step
6265
stepper.step({
6366
steps: 2000,
64-
direction: five.Stepper.DIRECTION.CW
65-
}, function() {
66-
console.log("Done moving CW");
67-
});
67+
direction: Stepper.DIRECTION.CW
68+
}, () => console.log("Done moving CW"));
6869
});
6970
});
7071

docs/stepper-four_wire.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!--remove-start-->
2+
3+
# Stepper - Four Wire
4+
5+
<!--remove-end-->
6+
7+
8+
9+
10+
11+
12+
##### Breadboard for "Stepper - Four Wire"
13+
14+
15+
16+
![docs/breadboard/stepper-four_wire.png](breadboard/stepper-four_wire.png)<br>
17+
18+
Fritzing diagram: [docs/breadboard/stepper-four_wire.fzz](breadboard/stepper-four_wire.fzz)
19+
20+
&nbsp;
21+
22+
23+
24+
25+
Run this example from the command line with:
26+
```bash
27+
node eg/stepper-four_wire.js
28+
```
29+
30+
31+
```javascript
32+
const {Board, Stepper} = require("johnny-five");
33+
const board = new Board();
34+
35+
board.on("ready", () => {
36+
/**
37+
* In order to use the Stepper class, your board must be flashed with
38+
* either of the following:
39+
*
40+
* - AdvancedFirmata https://github.com/soundanalogous/AdvancedFirmata
41+
* - ConfigurableFirmata https://github.com/firmata/arduino/releases/tag/v2.6.2
42+
*
43+
*/
44+
45+
const stepper = new Stepper({
46+
type: Stepper.TYPE.FOUR_WIRE,
47+
stepsPerRev: 200,
48+
pins: {
49+
motor1: 10,
50+
motor2: 11,
51+
motor3: 12,
52+
motor4: 13
53+
}
54+
});
55+
56+
// set stepp[er to 180 rpm, CCW, with acceleration and deceleration
57+
stepper.rpm(180).direction(Stepper.DIRECTION.CCW).accel(1600).decel(1600);
58+
59+
// make 10 full revolutions
60+
stepper.step(2000, () => {
61+
console.log("done moving CCW");
62+
63+
// once first movement is done, make 10 revolutions clockwise at previously
64+
// defined speed, accel, and decel by passing an object into stepper.step
65+
stepper.step({
66+
steps: 2000,
67+
direction: Stepper.DIRECTION.CW
68+
}, () => console.log("done moving CW"));
69+
});
70+
});
71+
72+
```
73+
74+
75+
76+
77+
78+
79+
80+
81+
&nbsp;
82+
83+
<!--remove-start-->
84+
85+
## License
86+
Copyright (c) 2012-2014 Rick Waldron <[email protected]>
87+
Licensed under the MIT license.
88+
Copyright (c) 2015-2019 The Johnny-Five Contributors
89+
Licensed under the MIT license.
90+
91+
<!--remove-end-->

docs/stepper-sweep.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ node eg/stepper-sweep.js
1818

1919

2020
```javascript
21-
var five = require("johnny-five");
22-
var board = new five.Board();
21+
const {Board, Stepper} = require("johnny-five");
22+
const board = new Board();
2323

24-
board.on("ready", function() {
24+
board.on("ready", () => {
2525
/**
2626
* In order to use the Stepper class, your board must be flashed with
2727
* either of the following:
@@ -31,16 +31,13 @@ board.on("ready", function() {
3131
*
3232
*/
3333

34-
var k = 0;
35-
var stepper = new five.Stepper({
36-
type: five.Stepper.TYPE.DRIVER,
34+
const stepper = new Stepper({
35+
type: Stepper.TYPE.DRIVER,
3736
stepsPerRev: 200,
3837
pins: [11, 12]
3938
});
4039

41-
stepper.rpm(180).ccw().step(2000, function() {
42-
console.log("done");
43-
});
40+
stepper.rpm(180).ccw().step(2000, () => console.log("done"));
4441
});
4542

4643
```

eg/stepper-driver.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var five = require("../lib/johnny-five");
2-
var board = new five.Board();
1+
const {Board, Stepper} = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
4+
board.on("ready", () => {
55

66
/**
77
* In order to use the Stepper class, your board must be flashed with
@@ -12,28 +12,29 @@ board.on("ready", function() {
1212
*
1313
*/
1414

15-
var stepper = new five.Stepper({
16-
type: five.Stepper.TYPE.DRIVER,
15+
const stepper = new Stepper({
16+
type: Stepper.TYPE.DRIVER,
1717
stepsPerRev: 200,
1818
pins: {
1919
step: 12,
2020
dir: 11
2121
}
2222
});
2323

24-
// Make 10 full revolutions counter-clockwise at 180 rpm with acceleration and deceleration
25-
stepper.rpm(180).ccw().accel(1600).decel(1600).step(2000, function() {
24+
// Set stepper to 180 RPM, counter-clockwise with acceleration and deceleration
25+
stepper.rpm(180).ccw().accel(1600).decel(1600);
26+
27+
// Make 10 full revolutions
28+
stepper.step(2000, () => {
2629

2730
console.log("Done moving CCW");
2831

2932
// once first movement is done, make 10 revolutions clockwise at previously
3033
// defined speed, accel, and decel by passing an object into stepper.step
3134
stepper.step({
3235
steps: 2000,
33-
direction: five.Stepper.DIRECTION.CW
34-
}, function() {
35-
console.log("Done moving CW");
36-
});
36+
direction: Stepper.DIRECTION.CW
37+
}, () => console.log("Done moving CW"));
3738
});
3839
});
3940

eg/stepper-four_wire.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
var five = require("../lib/johnny-five");
2-
var board = new five.Board();
3-
var Stepper = five.Stepper;
1+
const {Board, Stepper} = require("../lib/johnny-five");
2+
const board = new Board();
43

5-
board.on("ready", function() {
4+
board.on("ready", () => {
65
/**
76
* In order to use the Stepper class, your board must be flashed with
87
* either of the following:
@@ -12,7 +11,7 @@ board.on("ready", function() {
1211
*
1312
*/
1413

15-
var stepper = new Stepper({
14+
const stepper = new Stepper({
1615
type: Stepper.TYPE.FOUR_WIRE,
1716
stepsPerRev: 200,
1817
pins: {
@@ -23,17 +22,18 @@ board.on("ready", function() {
2322
}
2423
});
2524

26-
// make 10 full revolutions counter-clockwise at 180 rpm with acceleration and deceleration
27-
stepper.rpm(180).direction(Stepper.DIRECTION.CCW).accel(1600).decel(1600).step(2000, function() {
25+
// set stepp[er to 180 rpm, CCW, with acceleration and deceleration
26+
stepper.rpm(180).direction(Stepper.DIRECTION.CCW).accel(1600).decel(1600);
27+
28+
// make 10 full revolutions
29+
stepper.step(2000, () => {
2830
console.log("done moving CCW");
2931

3032
// once first movement is done, make 10 revolutions clockwise at previously
3133
// defined speed, accel, and decel by passing an object into stepper.step
3234
stepper.step({
3335
steps: 2000,
3436
direction: Stepper.DIRECTION.CW
35-
}, function() {
36-
console.log("done moving CW");
37-
});
37+
}, () => console.log("done moving CW"));
3838
});
3939
});

eg/stepper-sweep.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var five = require("../lib/johnny-five");
2-
var board = new five.Board();
1+
const {Board, Stepper} = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
4+
board.on("ready", () => {
55
/**
66
* In order to use the Stepper class, your board must be flashed with
77
* either of the following:
@@ -11,14 +11,11 @@ board.on("ready", function() {
1111
*
1212
*/
1313

14-
var k = 0;
15-
var stepper = new five.Stepper({
16-
type: five.Stepper.TYPE.DRIVER,
14+
const stepper = new Stepper({
15+
type: Stepper.TYPE.DRIVER,
1716
stepsPerRev: 200,
1817
pins: [11, 12]
1918
});
2019

21-
stepper.rpm(180).ccw().step(2000, function() {
22-
console.log("done");
23-
});
20+
stepper.rpm(180).ccw().step(2000, () => console.log("done"));
2421
});

tpl/programs.json

+4
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@
494494
"file": "stepper-driver.js",
495495
"title": "Stepper - Driver"
496496
},
497+
{
498+
"file": "stepper-four_wire.js",
499+
"title": "Stepper - Four Wire"
500+
},
497501
{
498502
"file": "stepper-sweep.js",
499503
"title": "Stepper - Sweep"

0 commit comments

Comments
 (0)