Last active
December 29, 2015 04:09
-
-
Save peterhellberg/7613185 to your computer and use it in GitHub Desktop.
Cylon robot with two LEDs and a Basic Force Sensing Resistor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to patch the Robot.prototype.requireDriver in
node_modules/cylon/dist/robot.js
in order to use multiple LEDs.GitHub Issue.