Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Last active December 29, 2015 04:09
Show Gist options
  • Save peterhellberg/7613185 to your computer and use it in GitHub Desktop.
Save peterhellberg/7613185 to your computer and use it in GitHub Desktop.
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
Copy link
Author

Sketch

@peterhellberg
Copy link
Author

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