Create a gist now

Instantly share code, notes, and snippets.

Turn your Sphero into a twitter watchbot
var Cylon = require('cylon');
var Twitter = require('twitter');
var iod = require('iod-node')
var iodclient= new iod.IODClient('http://api.idolondemand.com','<yourapikey>')
var twitterclient = new Twitter({
consumer_key: '<yourconsumerkey>',
consumer_secret: '<yourconsumersecret>',
access_token_key: '<youraccesstoken>',
access_token_secret: '<youraccesstokensecret>'
});
function watchdog(my){
twitterclient.stream('statuses/filter', {track: 'sphero'}, function(stream) {
stream.on('data', function(tweet) {
var data= {'text':tweet.text}
iodclient.call('analyzesentiment',function(err,resp,body){
var sentiment = body["aggregate"]["sentiment"];
my.sphero.setHeading(0)
my.sphero.roll(0,180) // Everytime the sphero will spin half a rotation
if (sentiment=="positive"){ my.sphero.setRGB(0x01DF74) } //Green
else if (sentiment == "negative"){ my.sphero.setRGB(0xFF3300) } //Red
else{ my.sphero.setRGB(0x0066FF) } //Blue for neutral
after((1).seconds(), function() { // Return to white
my.sphero.setRGB(0xFFFFFF)
});
},data)
});
stream.on('error', function(error) {
throw error;
});
});
}
a=Cylon.robot({
connections: {
sphero: { adaptor: 'sphero', port: '/dev/cu.Sphero-YBW-AMP-SPP' }
},
devices: {
sphero: { driver: 'sphero' }
},
work: watchdog
});
b=a.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment