Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active August 29, 2015 14:07
Show Gist options
  • Save deadprogram/86834a9078560bf711bc to your computer and use it in GitHub Desktop.
Save deadprogram/86834a9078560bf711bc to your computer and use it in GitHub Desktop.
var Cylon = require('cylon');
Cylon.robot({
connection: { name: 'sphero', adaptor: 'sphero', port: '/dev/tty.Sphero-YBW-RN-SPP' },
device: { name: 'sphero', driver: 'sphero' },
setColor: function(color) {
my.sphero.setColor(color);
},
work: function(my) {
var opts = {
n: 40,
m: 1,
pcnt: 0,
};
var max = 0;
my.sphero.detectCollisions();
my.sphero.setDataStreaming(['velocity'], opts);
my.sphero.on('data', function(data) {
x = Math.abs(data[0]);
y = Math.abs(data[1]);
if (x > max) max = x;
if (y > max) max = y;
});
every((1).second(), function() {
if (max < 5) {
my.sphero.setColor('blue');
} else if (max < 50) {
my.sphero.setColor('lightyellow');
} else if (max < 100) {
my.sphero.setColor('yellow');
} else if (max < 150) {
my.sphero.setColor('orange');
} else if (max < 200) {
my.sphero.setColor('orangered');
} else if (max < 250) {
my.sphero.setColor('darkorange');
} else if (max < 300) {
my.sphero.setColor('mediumvioletred');
} else if (max < 400) {
my.sphero.setColor('orangered');
} else if (max < 450) {
my.sphero.setColor('palevioletred');
} else if (max < 500) {
my.sphero.setColor('red');
} else {
my.sphero.setColor('darkred');
}
max = 0;
});
}
}).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment