Merge pull request #15 from hybridgroup/9-motor-driver
Adds motor driver example and led brightness.
This commit is contained in:
commit
ac8f220880
|
@ -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()
|
|
@ -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()
|
Loading…
Reference in New Issue