-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
70 lines (55 loc) · 1.68 KB
/
bot.js
File metadata and controls
70 lines (55 loc) · 1.68 KB
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
66
67
68
69
70
var five = require("johnny-five");
var EtherPortClient = require("etherport-client").EtherPortClient;
var Bot = {
leftFwd: function() {},
leftRev: function() {},
rightFwd: function() {},
rightRev: function() {},
init: init
};
function init(cb) {
var bot = new five.Board({
port: new EtherPortClient({
host: "192.168.2.158", // Put your individual IP address here.
port: 3030
}),
timeout: 1e5
});
bot.on("ready", function () {
// The following code will blink the LED on the WeMos board to indicate that the code is working.
var state = 1;
setInterval(function () {
this.digitalWrite(2, (state ^= 1));
}.bind(this), 500);
// Use Johnny-Five to create an instance of the left motor.
var leftWheel = new five.Motor({
pins: {
pwm: 0,
dir: 4
},
invertPWM: true
});
// Use Johnny-Five to create an instance of the right motor
var rightWheel = new five.Motor({
pins: {
pwm: 13,
dir: 12
},
invertPWM: true
});
Bot.leftFwd = function(speed) {
speed ? leftWheel.fwd(speed) : leftWheel.stop();
};
Bot.rightFwd = function(speed) {
speed ? rightWheel.fwd(speed) : rightWheel.stop();
};
Bot.leftRev = function(speed) {
speed ? leftWheel.rev(speed) : leftWheel.stop();
};
Bot.rightRev = function(speed) {
speed ? rightWheel.rev(speed) : rightWheel.stop();
};
cb();
});
}
module.exports = Bot;