-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservo.js
46 lines (36 loc) · 1.03 KB
/
servo.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
'use strict';
// Define the objects you will be working with
var five = require ("johnny-five");
var Shield = require("j5-sparkfun-weather-shield")(five);
// Add the following definition for the Particle plugin for Johnny-Five
var Particle = require("particle-io");
var board = new five.Board({
io: new Particle({
token: '1b67fbedf478e95d045fa7cf08bd9c78b182ab6b',
deviceId: '1f001f000347353138383138'
})
});
// The board.on() executes the anonymous function when the
// board reports back that it is initialized and ready.
board.on("ready", function() {
console.log("Board connected...");
var servo1 = new five.Servo({
pin: 'D1',
startAt: 0
});
var servo2 = new five.Servo({
pin: 'D2',
startAt: 0
});
var angle = 0;
var step = 10;
setInterval(function() {
angle += step;
if (angle > 180 || angle < 0) {
step *= -1;
}
console.log('Angle', angle)
servo1.to(angle);
servo2.to(angle);
}, 1000);
});