-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracks.js
52 lines (44 loc) · 1.1 KB
/
tracks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
function Tracks(board, five) {
this.motors = {
left: new five.Motor({
pins: {
pwm: 3,
dir: 2,
cdir: 4
}
}),
right: new five.Motor({
pins: {
pwm: 5,
dir: 6,
cdir: 7
}
})
};
}
Tracks.prototype.forward = function (speed) {
var mSpeed = speed || 255;
this.motors.left.forward(mSpeed);
this.motors.right.forward(mSpeed);
};
Tracks.prototype.reverse = function (speed) {
var mSpeed = speed || 255;
this.motors.left.reverse(mSpeed);
this.motors.right.reverse(mSpeed);
};
Tracks.prototype.left = function (speed) {
var mSpeed = speed || 255;
this.motors.right.forward(mSpeed);
this.motors.left.reverse(mSpeed);
};
Tracks.prototype.right = function (speed) {
var mSpeed = speed || 255;
this.motors.right.reverse(mSpeed);
this.motors.left.forward(mSpeed);
};
Tracks.prototype.stop = function () {
this.motors.right.stop();
this.motors.left.stop();
};
module.exports = Tracks;