From b37fe4a99e6e461f45c55b22fc534aa178269683 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Wed, 30 Oct 2013 16:04:52 -0600 Subject: [PATCH 1/3] Added examples for motor speed and led brightness. --- examples/led_brightness.coffee | 20 ++++++++++++++++++++ examples/motor.coffee | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/led_brightness.coffee create mode 100644 examples/motor.coffee diff --git a/examples/led_brightness.coffee b/examples/led_brightness.coffee new file mode 100644 index 0000000..6eeff84 --- /dev/null +++ b/examples/led_brightness.coffee @@ -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() diff --git a/examples/motor.coffee b/examples/motor.coffee new file mode 100644 index 0000000..985683e --- /dev/null +++ b/examples/motor.coffee @@ -0,0 +1,19 @@ +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) + increment = -increment if (speed is 0) or (speed is 255) + +.start() From 6a9c5eb60e2529b6570ff60742c6f88eeb2bc579 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Wed, 30 Oct 2013 16:21:17 -0600 Subject: [PATCH 2/3] Added speed output to the example. --- examples/motor.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/motor.coffee b/examples/motor.coffee index 985683e..7f7bdaf 100644 --- a/examples/motor.coffee +++ b/examples/motor.coffee @@ -14,6 +14,7 @@ Cylon.robot every 0.05.seconds(), -> speed += increment my.motor.speed(speed) + console.log("current speed => #{ my.motor.driver.currentSpeed }") increment = -increment if (speed is 0) or (speed is 255) .start() From ea472f9e129462339a5c347ee9b6189ff3729ff3 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Wed, 30 Oct 2013 20:37:42 -0600 Subject: [PATCH 3/3] Fix issue with currentSpeed having to go through driver. --- examples/motor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/motor.coffee b/examples/motor.coffee index 7f7bdaf..7c8ecb3 100644 --- a/examples/motor.coffee +++ b/examples/motor.coffee @@ -14,7 +14,7 @@ Cylon.robot every 0.05.seconds(), -> speed += increment my.motor.speed(speed) - console.log("current speed => #{ my.motor.driver.currentSpeed }") + console.log("current speed => #{ my.motor.currentSpeed() }") increment = -increment if (speed is 0) or (speed is 255) .start()