Skip to content

Commit 750c07c

Browse files
committed
firmataAccelStepper
First commit
1 parent 0523f58 commit 750c07c

File tree

7 files changed

+1193
-128
lines changed

7 files changed

+1193
-128
lines changed

examples/stepper-accel.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var Board = require("../");
2+
3+
Board.requestPort(function(error, port) {
4+
if (error) {
5+
console.log(error);
6+
return;
7+
}
8+
9+
var board = new Board(port.comName);
10+
11+
board.on("ready", function() {
12+
13+
board.accelStepperConfig({
14+
deviceNum: 0,
15+
type: board.STEPPER.TYPE.FOUR_WIRE,
16+
motorPin1: 5,
17+
motorPin2: 6,
18+
motorPin3: 7,
19+
motorPin4: 8,
20+
stepType: board.STEPPER.STEPTYPE.WHOLE
21+
});
22+
23+
board.accelStepperSpeed(0, 400);
24+
board.accelStepperAcceleration(0, 100);
25+
board.accelStepperStep(0, 2000);
26+
27+
board.on("stepper-done-0", function(position) {
28+
console.log("Current position: " + position);
29+
});
30+
31+
});
32+
});

examples/stepper-driver.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var Board = require("../");
2+
3+
Board.requestPort(function(error, port) {
4+
if (error) {
5+
console.log(error);
6+
return;
7+
}
8+
9+
var board = new Board(port.comName);
10+
11+
board.on("ready", function() {
12+
13+
board.accelStepperConfig({
14+
deviceNum: 0,
15+
type: board.STEPPER.TYPE.DRIVER,
16+
stepPin: 5,
17+
directionPin: 6,
18+
enablePin: 2,
19+
invertPins: [2]
20+
});
21+
22+
board.accelStepperSpeed(0, 400);
23+
board.accelStepperAcceleration(0, 100);
24+
board.accelStepperEnable(0, true);
25+
board.accelStepperStep(0, 200);
26+
27+
board.on("stepper-done-0", function(position) {
28+
console.log("Current position: " + position);
29+
});
30+
31+
});
32+
});

examples/stepper-multi.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var Board = require("../");
2+
3+
Board.requestPort(function(error, port) {
4+
if (error) {
5+
console.log(error);
6+
return;
7+
}
8+
9+
var board = new Board(port.comName);
10+
11+
board.on("ready", function() {
12+
13+
board.accelStepperConfig({
14+
deviceNum: 0,
15+
type: board.STEPPER.TYPE.FOUR_WIRE,
16+
motorPin1: 5,
17+
motorPin2: 6,
18+
motorPin3: 7,
19+
motorPin4: 8,
20+
stepType: board.STEPPER.STEPTYPE.WHOLE
21+
});
22+
23+
board.accelStepperConfig({
24+
deviceNum: 1,
25+
type: board.STEPPER.TYPE.FOUR_WIRE,
26+
motorPin1: 9,
27+
motorPin2: 10,
28+
motorPin3: 11,
29+
motorPin4: 12,
30+
stepType: board.STEPPER.STEPTYPE.HALF
31+
});
32+
33+
board.accelStepperSpeed(0, 400);
34+
board.accelStepperSpeed(1, 400);
35+
36+
board.multiStepperConfig({
37+
groupNum: 0,
38+
devices: [0, 1]
39+
});
40+
41+
board.multiStepperTo(0, [2000, 3000]);
42+
43+
board.on("multi-stepper-done-0", function() {
44+
board.accelStepperReportPosition(0);
45+
board.accelStepperReportPosition(1);
46+
});
47+
48+
board.on("stepper-position-0", function(value) {
49+
console.log("Stepper 0 position: " + value);
50+
});
51+
52+
board.on("stepper-position-1", function(value) {
53+
console.log("Stepper 1 position: " + value);
54+
});
55+
56+
});
57+
});

examples/stepper-three-wire.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var Board = require("../");
2+
3+
Board.requestPort(function(error, port) {
4+
if (error) {
5+
console.log(error);
6+
return;
7+
}
8+
9+
var board = new Board(port.comName);
10+
11+
board.on("ready", function() {
12+
13+
board.accelStepperConfig({
14+
deviceNum: 0,
15+
type: board.STEPPER.TYPE.THREE_WIRE,
16+
motorPin1: 2,
17+
motorPin2: 3,
18+
motorPin3: 4
19+
});
20+
21+
board.accelStepperSpeed(0, 100);
22+
board.accelStepperStep(0, 1000);
23+
24+
board.on("stepper-done-0", function(position) {
25+
console.log("Current position: " + position);
26+
});
27+
28+
});
29+
});

0 commit comments

Comments
 (0)