-
Notifications
You must be signed in to change notification settings - Fork 1
/
motors.js
65 lines (56 loc) · 1.33 KB
/
motors.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
53
54
55
56
57
58
59
60
61
62
63
64
65
var exec = require('child_process').exec;
/**
* Control Motors
*/
function Motors() {
// initialize
exec('gpio -g mode 18 pwm');
exec('gpio -g mode 22 out');
exec('gpio -g mode 23 out');
exec('gpio -g mode 24 out');
exec('gpio -g mode 25 out');
}
/**
* Class definition
*/
Motors.prototype = {
go : function() {
//console.log('Motors.go()');
exec('gpio -g write 22 1');
exec('gpio -g write 23 0');
exec('gpio -g write 24 1');
exec('gpio -g write 25 0');
},
left : function() {
//console.log('Motors.left()');
exec('gpio -g write 22 0');
exec('gpio -g write 23 0');
exec('gpio -g write 24 1');
exec('gpio -g write 25 0');
},
right : function() {
//console.log('Motors.right()');
exec('gpio -g write 22 1');
exec('gpio -g write 23 0');
exec('gpio -g write 24 0');
exec('gpio -g write 25 0');
},
back : function() {
//console.log('Motors.back()');
exec('gpio -g write 22 0');
exec('gpio -g write 23 1');
exec('gpio -g write 24 0');
exec('gpio -g write 25 1');
},
stop : function() {
//console.log('Motors.stop()');
exec('gpio -g write 22 0');
exec('gpio -g write 23 0');
exec('gpio -g write 24 0');
exec('gpio -g write 25 0');
},
pwm : function(duty) {
exec('gpio -g pwm 18 ' + duty);
}
};
module.exports = Motors;