Sphero Collision event example.

This commit is contained in:
Edgar O Silva 2013-10-28 19:50:37 -06:00
parent 5da9ac3216
commit 507e381ae6
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
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) ->
me.sphero.setRGB(color)
Logger.info 'collision:'
console.log("color: #{ parseInt(color, 16) } ")
color = color ^ bitFilter
me.sphero.roll 60, Math.floor(Math.random() * 360)
every 1.second, ->
me.sphero.roll 90, Math.floor(Math.random() * 360)
.start()