Merge pull request #11 from hybridgroup/12-add-collision-event
Sphero Collision event example.
This commit is contained in:
commit
83f5e6c4c3
|
@ -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()
|
|
@ -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:'
|
||||
|
|
Loading…
Reference in New Issue