Merge pull request #15 from hybridgroup/9-motor-driver

Adds motor driver example and led brightness.
This commit is contained in:
Ron Evans 2013-10-30 19:47:00 -07:00
commit ac8f220880
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,20 @@
Cylon = require('..')
# Initialize the robot
Cylon.robot
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'led', driver: 'led', pin: 3
work: (my) ->
# we do our thing here
brightness = 0
fade = 5
every 0.05.seconds(), ->
brightness += fade
my.led.brightness(brightness)
fade = -fade if (brightness is 0) or (brightness is 255)
.start()

20
examples/motor.coffee Normal file
View File

@ -0,0 +1,20 @@
Cylon = require('..')
# Initialize the robot
Cylon.robot
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'motor', driver: 'motor', pin: 3
work: (my) ->
speed = 0
increment = 5
every 0.05.seconds(), ->
speed += increment
my.motor.speed(speed)
console.log("current speed => #{ my.motor.currentSpeed() }")
increment = -increment if (speed is 0) or (speed is 255)
.start()