From 046c3578a5e0d5b3df578ba39fc17546edb0f02a Mon Sep 17 00:00:00 2001 From: deadprogram Date: Thu, 24 Oct 2013 16:19:15 -0700 Subject: [PATCH] More examples please --- examples/sphero_messages.coffee | 22 ++++++++++++++++++++++ examples/sphero_multiple.coffee | 31 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 examples/sphero_messages.coffee create mode 100644 examples/sphero_multiple.coffee diff --git a/examples/sphero_messages.coffee b/examples/sphero_messages.coffee new file mode 100644 index 0000000..09da42c --- /dev/null +++ b/examples/sphero_messages.coffee @@ -0,0 +1,22 @@ +Cylon = require('..') + +Cylon.robot + connection: + name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' + + device: + name: 'sphero', driver: 'sphero' + + work: (me) -> + me.sphero.on 'connect', -> + Logger.info 'party started...' + + me.sphero.on 'message', (data) -> + Logger.info 'message:' + Logger.info data + + me.sphero.on 'notification', (data) -> + Logger.info 'notification:' + Logger.info data + +.start() diff --git a/examples/sphero_multiple.coffee b/examples/sphero_multiple.coffee new file mode 100644 index 0000000..c1512e7 --- /dev/null +++ b/examples/sphero_multiple.coffee @@ -0,0 +1,31 @@ +Cylon = require '..' + +bots = [ + { port: '/dev/rfcomm0', name: 'Thelma' }, + { port: '/dev/rfcomm1', name: 'Louise' } +] + +SpheroRobot = + connection: + name: 'Sphero', adaptor: 'sphero' + + device: + name: 'sphero', driver: 'sphero' + + work: (self) -> + color = 0x000050 + every 1.second(), -> + #me.sphero.roll(60, Math.floor(Math.random() * 360), 1) + Logger.info self.name + self.sphero.setRGB(color, true) + color += 0x005000 + color = 0x000050 if color > 0xFFFFFF + +for bot in bots + robot = Object.create(SpheroRobot) + robot.connection.port = bot.port + robot.name = bot.name + + Cylon.robot robot + +Cylon.start()