Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cylon robot with two LEDs and a Basic Force Sensing Resistor
fs = require('fs')
isUSBModem = (element) ->
element.match(/^cu.usbmodem\d+/)
device = fs.readdirSync('/dev').filter(isUSBModem)[0]
Cylon = require('cylon')
Cylon.robot
name: 'acb-cylon'
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/' + device
devices:
[
{ name: 'green', pin: 12, driver: 'led' },
{ name: 'red', pin: 11, driver: 'led' },
{ name: 'button', pin: 2, driver: 'button' },
{ name: 'sensor', driver: 'analogSensor', pin: 0, lowerLimit: 200, upperLimit: 400 }
]
work: (my) ->
my.button.on 'push', ->
console.log('button!')
my.red.toggle()
my.sensor.on 'lowerLimit', ->
my.green.turnOff()
my.sensor.on 'analogRead', (val) ->
if val > 0
console.log(val)
my.sensor.on 'upperLimit', (val) ->
my.green.turnOn()
Cylon.api(host: '0.0.0.0', port: '5432')
Cylon.start()
@peterhellberg

This comment has been minimized.

Copy link
Owner Author

commented Nov 23, 2013

Sketch

@peterhellberg

This comment has been minimized.

Copy link
Owner Author

commented Nov 23, 2013

I had to patch the Robot.prototype.requireDriver in node_modules/cylon/dist/robot.js in order to use multiple LEDs.

GitHub Issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.