Merge pull request #11 from hybridgroup/12-add-collision-event

Sphero Collision event example.
This commit is contained in:
Ron Evans 2013-10-28 19:03:21 -07:00
commit 83f5e6c4c3
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,29 @@
Cylon = require('..')
Cylon.robot
connection:
name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0'
device:
name: 'sphero', driver: 'sphero'
work: (me) ->
color = 0x00FF00
bitFilter = 0xFFFF00
me.sphero.on('connect', ->
Logger.info('Setting up Collision Detection...')
me.sphero.detectCollisions()
me.sphero.setRGB(color)
)
me.sphero.on 'collision', (data) ->
Logger.info 'collision:'
color = color ^ bitFilter
console.log("color: #{ color.toString(16) } ")
me.sphero.setRGB(color)
every 1.second, ->
me.sphero.roll 90, Math.floor(Math.random() * 360)
.start()

View File

@ -20,6 +20,11 @@ Cylon.robot
Logger.info 'message:'
Logger.info data
me.sphero.on 'collision', (data) ->
me.sphero.setRGB(0xFF0000)
Logger.info 'collision:'
Logger.info data
me.sphero.on 'notification', (data) ->
me.sphero.setRGB(0xFF0000)
Logger.info 'notification:'