-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (57 loc) · 1.82 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var five = require("johnny-five");
// The Johnny Five REPL is on by default
// To deactivate it just add change to
// var board = new five.Board({repl: false});
var board = new five.Board();
board.on("ready", function () {
// Load the Config for the Arduino Motor Shield
var configs = five.Motor.SHIELD_CONFIGS.ADAFRUIT_V1;
// Configure the driving motors
var motor1 = new five.Motor(configs.M3);
var motor2 = new five.Motor(configs.M4);
// If REPL is inactivate, comment this out, else error!
// This injects the motor objects into the REPL, so they can be used like: m1.stop()
this.repl.inject({
m1: motor1,
m2: motor2
});
// Some example event handlers for the driving motors
motor1.on("start", function () {
console.log("Start M1", Date.now());
});
motor2.on("start", function () {
console.log("Start M2", Date.now());
});
motor1.on("stop", function () {
console.log("Stop M1", Date.now());
});
motor2.on("stop", function () {
console.log("Stop M2", Date.now());
});
motor1.on("forward", function () {
console.log("Forward M1", Date.now());
board.wait(1000, function () {
motor1.reverse(150);
});
});
motor1.on("reverse", function () {
console.log("Reverse M1", Date.now());
board.wait(1000, function () {
motor1.stop();
});
});
motor2.on("forward", function () {
console.log("Forward M2", Date.now());
board.wait(1000, function () {
motor2.reverse(150);
});
});
motor2.on("reverse", function () {
console.log("Reverse M2", Date.now());
board.wait(1000, function () {
motor2.stop();
});
});
motor1.forward(150);
motor2.forward(150);
});