Skip to content

Commit df32d23

Browse files
author
Amadeus Stevenson
committed
Update for reversed servo
1 parent 3f4ebb4 commit df32d23

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

leap-arduino.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ board.on('ready', function() {
1010
led = new five.Led(13);
1111
ws.on('message', function(data, flags) {
1212
frame = JSON.parse(data);
13-
if (frame.hands && frame.hands.length >= 1) {
13+
if (frame.hands && frame.hands.length == 1) {
1414
led.on();
1515
} else {
1616
led.off();

servo.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var webSocket = require('ws'),
66
five = require('johnny-five'),
77
board = new five.Board(),
88
// mm range of leap motion to use, see leap-range.js to find
9-
leap_range = [-350,250], // x of right hand
9+
leap_range = [-100,100], // x of right hand
1010
frame, palm;
1111

1212
// parse the data and respond
@@ -28,7 +28,7 @@ board.on('ready', function() {
2828
palm = frame.hands[0].palmPosition;
2929
// map x position of leap to servo
3030
//console.log("input",palm[0]);
31-
//console.log("output", palm[0].map())
31+
console.log("output", palm[0].map())
3232
servo.to(palm[0].map());
3333
}
3434
});
@@ -41,5 +41,7 @@ Number.prototype.map = function () {
4141
// check output is within range, or cap
4242
output = (output > servo.range[1]) ? servo.range[1] : output;
4343
output = (output < servo.range[0]) ? servo.range[0] : output;
44+
// is the servo range reversed? uncomment below
45+
output = servo.range[1] - output;
4446
return output;
4547
}

six-servos.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44

55
leap_ranges = Array(
66
Array(
7-
Array(-150,200),
8-
Array(50,350),
9-
Array(-100,200)
7+
Array(-250,100),
8+
Array(70,550),
9+
Array(-100,250)
1010
),
1111
Array(
12-
Array(-225,200),
13-
Array(40,380),
14-
Array(-100,175)
12+
Array(-350,270),
13+
Array(40,550),
14+
Array(-80,250)
1515
)
1616
);
1717

1818
servo_ranges = Array(
1919
Array(
2020
Array(0,179),
21-
Array(50,150),
21+
Array(0,179),
2222
Array(0,179)
2323
),
2424
Array(

0 commit comments

Comments
 (0)