Skip to content

Instantly share code, notes, and snippets.

@4kategreen
Created January 16, 2014 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4kategreen/8450520 to your computer and use it in GitHub Desktop.
Save 4kategreen/8450520 to your computer and use it in GitHub Desktop.
ng-conf team DSR's sphero hokey pokey dance
var Cylon = require('cylon');
Cylon.robot({
connection: { name: 'sphero', adaptor: 'sphero', port: '/dev/cu.Sphero-RRY-AMP-SPP' },
device: { name: 'sphero', driver: 'sphero' },
work: function(my) {
var on = false,
dir = 0,
beat = 0,
interval;
every((0.9).second(), function() {
beat++;
switch(beat) {
case 1:
case 5:
my.sphero.roll(150,190);
break;
// stop
case 2:
case 4:
case 6:
case 10:
my.sphero.stop();
break;
// out
case 3:
my.sphero.roll(150,10);
break;
// shake
case 7:
var angle = 0;
interval = setInterval(function() {
my.sphero.roll(80,angle);
my.sphero.setRGB(Math.floor(Math.random() * 16000000));
angle+= 50;
if (angle > 359) {
angle = 50;
}
}, 100);
break;
case 11:
var angle = 0,
speed = 75;
clearInterval(interval);
my.sphero.stop();
interval = setInterval(function() {
angle+= 60;
if (angle > 359) {
angle = 10;
}
my.sphero.roll(speed, angle);
}, 300);
break;
case 15:
clearInterval(interval);
my.sphero.stop();
beat = -1;
break;
}
});
// every((1).second(), function() {
// my.sphero.roll(150,dir);
// dir+=180;
// if (dir === 360) dir = 0;
// // flash light
// if (on) {
// my.sphero.setColor("blue");
// on = false;
// } else {
// my.sphero.setColor('orange');
// on = true;
// }
// });
my.sphero.on('collision', function(data) {
console.log(data);
console.log("Collision:");
//color = color ^ bitFilter;
//console.log("Color: " + (color.toString(16)) + " ");
//my.sphero.setRGB(color);
//my.sphero.roll(100, Math.floor(Math.random() * 360));
});
}
})
Cylon.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment