Permalink
Browse files

Update with a servo.

  • Loading branch information...
1 parent 45b9fb8 commit 97e2b4ba5f4675a35081eb248f2b520b45262ccc Chris Williams committed Oct 6, 2012
Showing with 102 additions and 1 deletion.
  1. +2 −1 wii-drone.js
  2. +96 −0 wii-servo.js
  3. +4 −0 wire-mapping.txt
View
@@ -75,14 +75,15 @@ WiiDrone.prototype.handleDown = function(err, event) {
}
this.emit('down', err, event, buttonId, this);
}
-board = new five.Board({ debug: true});
+board = new five.Board({ debug: true});
board.on("ready", function() {
var wiiDrone = new WiiDrone();
var classicController = five.Nunchuk({ pins: ["A4", "A5"], freq: 100, device: "RVL-005" });
board.repl.inject({
sensor: classicController
});
classicController.on("up", function(err, event) {
+ console.log(event);
history.unshift(event.target.which);
history.length = KONAMI.length;
if(isKonami()) {
View
@@ -0,0 +1,96 @@
+var five = require("johnny-five");
+board = new five.Board({ debug: true});
+board.on("ready", function() {
+ var classicController = five.Nunchuk({ pins: ["A4", "A5"], freq: 100, device: "RVL-005" });
+ var servo1 = five.Servo({pin: 9});
+ var servo2 = five.Servo({pin: 10});
+ var servo3 = five.Servo({pin: 11});
+ board.repl.inject({
+ sensor: classicController
+ });
+
+ board.repl.inject({
+ servo: servo1
+ });
+
+ board.repl.inject({
+ servo: servo2
+ });
+
+ board.repl.inject({
+ servo: servo3
+ });
+
+ var max = 42;
+ var min = 20;
+ var range = max -min;
+ servo1.move(min);
+ servo2.move(min);
+ servo3.move(min);
+
+
+ var allUp = function () {
+ position = min;
+ moveServos(position);
+ }
+
+ var allDown = function () {
+ position = max;
+ moveServos(position);
+ }
+
+ var stepUp = function () {
+ position = Math.min(max, position + increment);
+ moveServos(position);
+ }
+ var stepDown = function () {
+ position = Math.min(max, position - increment);
+ moveServos(position);
+ }
+ var toggle = 0;
+ var dance = function () {
+ console.log("dance");
+ servo1.move(parseInt((Math.random() * range)+min, 10));
+ servo2.move(parseInt((Math.random() * range)+min, 10));
+ servo3.move(parseInt((Math.random() * range)+min, 10));
+ };
+ var dancer;
+
+ var moveServos = function(value) {
+ servo1.move(value);
+ servo2.move(value);
+ servo3.move(value);
+ }
+
+ var action = null;
+ var doing = null;
+ var position = min;
+ var increment = 2;
+ servo.on("error", function () { console.log(arguments);})
+ classicController.on("up", function(err, event) {
+ if (action) {
+ clearInterval(action)
+ action = null;
+ }
+ });
+ classicController.on("down", function(err, event) {
+ if (event.target.which == 'up') {
+ allUp()
+ } else if (event.target.which == 'down') {
+ allDown();
+ } else if (event.target.which == 'start') {
+ if (!dancer)
+ dancer = setInterval(dance, 500);
+
+ }else if (event.target.which == 'select') {
+ if (dancer){
+ clearInterval(dancer);
+ dancer=null;
+ }
+ }else if (event.target.which == 'x') {
+ action = setInterval(stepUp, 100);
+ }else if (event.target.which == 'y') {
+ action = setInterval(stepDown, 100);
+ }
+ });
+});
View
@@ -0,0 +1,4 @@
+Y => sck
+W => GND
+R => 5v
+G => SDA

0 comments on commit 97e2b4b

Please sign in to comment.