From 0dbf703ed990a40f4eb9259a1f83c3d379d036b7 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Mon, 30 Dec 2013 17:38:28 -0600 Subject: [PATCH 1/3] Remove duplicated example for blinkm in raspi. --- examples/raspi_i2c/raspi_i2c_blinkm.coffee | 2 +- examples/raspi_i2c_blinkm.coffee | 48 ---------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 examples/raspi_i2c_blinkm.coffee diff --git a/examples/raspi_i2c/raspi_i2c_blinkm.coffee b/examples/raspi_i2c/raspi_i2c_blinkm.coffee index 7c02216..d69c717 100644 --- a/examples/raspi_i2c/raspi_i2c_blinkm.coffee +++ b/examples/raspi_i2c/raspi_i2c_blinkm.coffee @@ -1,4 +1,4 @@ -Cylon = require('..') +Cylon = require('../..') Cylon.robot connection: diff --git a/examples/raspi_i2c_blinkm.coffee b/examples/raspi_i2c_blinkm.coffee deleted file mode 100644 index d69c717..0000000 --- a/examples/raspi_i2c_blinkm.coffee +++ /dev/null @@ -1,48 +0,0 @@ -Cylon = require('../..') - -Cylon.robot - connection: - name: 'raspi', adaptor: 'raspi' - - device: - name: 'pixel', driver: 'blinkm' - - work: (my) -> - - # Before you can use and work with I2C in the raspberry pi you - # need to configure it, follow the instructions to enable it here: - # - # http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c - - # We first stop the BlinkM light script - my.pixel.stopScript() - - # You can pass a callback to all blinkm functions as the last param, - # If you do the command would be executed asynchronously. - # For write operations you get an (err) param passed back, - # null/undefined for success, and containing the error y any encountered. - - # BlimkM Write Commands. - my.pixel.goToRGB(255, 0, 0) - my.pixel.fadeToRGB(0, 255, 0) - my.pixel.fadeToRGB(0, 0, 255) - #my.pixel.fadeToHSB(100, 180, 90) - #my.pixel.fadeToRandomRGB(0, 0, 255) - #my.pixel.fadeToRandomHSB(100, 180, 90) - #my.pixel.playLightScript(1, 0, 0) - #my.pixel.stopScript() - #my.pixel.setFadeSpeed(50) - #my.pixel.setTimeAdjust(50) - - # For read commands you get (err, data) passed back to the callback, - # data contains the read data buffer, in case of Sync call (no callback) - # you get a regular return with the data buffer. - color = my.pixel.getRGBColor() - console.log(color) - - # Example getting the color usinc async call and a callback - my.pixel.getRGBColor((err, data) -> - console.log(data) unless err? - ) - -.start() From 16bdfaf1416fbd165f74e690519c909cba6fd6c5 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Tue, 31 Dec 2013 16:32:50 -0600 Subject: [PATCH 2/3] Added updated example for blinkm driver using firmata on arduino. --- examples/blinkm/blinkm.coffee | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/blinkm/blinkm.coffee b/examples/blinkm/blinkm.coffee index e6e4812..a27d10a 100644 --- a/examples/blinkm/blinkm.coffee +++ b/examples/blinkm/blinkm.coffee @@ -1,26 +1,30 @@ Cylon = require '../..' Cylon.robot - connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' } + connection: + name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' - device: { name: 'blinkm', driver: 'blinkm' } + device: + name: 'blinkm', driver: 'blinkm' work: (my) -> my.blinkm.on 'start', -> - my.blinkm.version (version) -> - console.log "Started BlinkM version #{version}" + my.blinkm.stopScript() + my.blinkm.goToRGB(255, 0, 0) + my.blinkm.getFirmware((version) -> + Logger.info "Started BlinkM version #{version}" + ) - my.blinkm.off() - lit = false + my.blinkm.goToRGB(0,0,0) - every 1.second(), -> - if lit - lit = false - console.log 'on' - my.blinkm.rgb 0xaa, 0, 0 - else - lit = true - console.log 'off' - my.blinkm.rgb 0, 0, 0 + my.blinkm.getRGBColor((data) -> + console.log("Starting Color: #{ data }") + ) + + every 2.second(), () -> + my.blinkm.getRGBColor((data) -> + console.log("Current Color: #{ data }") + ) + my.blinkm.fadeToRandomRGB(128, 128, 128) .start() From 3f235a14d36be51aec1079d2159a9116c91a13ed Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Sun, 5 Jan 2014 16:55:53 -0600 Subject: [PATCH 3/3] Updated blinkm examples. --- examples/blinkm/blinkm.coffee | 2 +- examples/blinkm/blinkm.js | 29 ++++++++++--------- examples/blinkm/blinkm.litcoffee | 48 ++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/examples/blinkm/blinkm.coffee b/examples/blinkm/blinkm.coffee index a27d10a..9010a80 100644 --- a/examples/blinkm/blinkm.coffee +++ b/examples/blinkm/blinkm.coffee @@ -10,7 +10,7 @@ Cylon.robot work: (my) -> my.blinkm.on 'start', -> my.blinkm.stopScript() - my.blinkm.goToRGB(255, 0, 0) + my.blinkm.getFirmware((version) -> Logger.info "Started BlinkM version #{version}" ) diff --git a/examples/blinkm/blinkm.js b/examples/blinkm/blinkm.js index f3677ec..fc78668 100644 --- a/examples/blinkm/blinkm.js +++ b/examples/blinkm/blinkm.js @@ -7,24 +7,23 @@ Cylon.robot({ work: function(my) { my.blinkm.on('start', function() { - my.blinkm.version(function(version) { - console.log("Started BlinkM version " + version); + + my.blinkm.stopScript(); + + my.blinkm.getFirmware(function(version) { + Logger.info("Started BlinkM version " + version); }); - my.blinkm.off(); + my.blinkm.goToRGB(0,0,0); + my.blinkm.getRGBColor(function(data){ + console.log("Starting Color: #{ data }") + }); - var lit = false; - - every((1).second(), function() { - if (lit) { - lit = false; - console.log('on'); - my.blinkm.rgb(0xaa, 0, 0); - } else { - lit = true; - console.log('off'); - my.blinkm.rgb(0, 0, 0); - } + every((2).second(), function() { + my.blinkm.getRGBColor(function(data){ + console.log("Current Color: #{ data }"); + }); + my.blinkm.fadeToRandomRGB(128, 128, 128); }); }); } diff --git a/examples/blinkm/blinkm.litcoffee b/examples/blinkm/blinkm.litcoffee index 8bee395..330665d 100644 --- a/examples/blinkm/blinkm.litcoffee +++ b/examples/blinkm/blinkm.litcoffee @@ -13,13 +13,15 @@ With Cylon imported, we can start defining our robot. Cylon.robot -Our robot will be using an Arduino, and communicating over the Firmata protocol: +Our robot will be using an Arduino, and communicating over the Firmata protocol - connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' } + connection: + name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' And we'll have one device, a BlinkM led. - device: { name: 'blinkm', driver: 'blinkm' } + device: + name: 'blinkm', driver: 'blinkm' We'll now set up our robot's work. @@ -29,29 +31,33 @@ When the BlinkM sends the 'start' event, we'll set up our events my.blinkm.on 'start', -> -We'll request the BlinkM's version, and print that to the console: +We stop the default BlinkM's light script - my.blinkm.version (version) -> - console.log "Started BlinkM version #{version}" + my.blinkm.stopScript() -By default, we'll turn the LED off and assign a boolean that we'll use to -determine if it's on or not: +We'll request the BlinkM's version, and print that to the console - my.blinkm.off() - lit = false + my.blinkm.getFirmware((version) -> + Logger.info "Started BlinkM version #{version}" + ) -Now, every second, we'll toggle the LED, using the `lit` variable to determine -which state we need to transition the BlinkM to: +By default, we'll turn the LED off - every 1.second(), -> - if lit - lit = false - console.log 'on' - my.blinkm.rgb 0xaa, 0, 0 - else - lit = true - console.log 'off' - my.blinkm.rgb 0, 0, 0 + my.blinkm.goToRGB(0,0,0) + +We print the default starting color (in this case 0,0,0 since we turned the led off) + + my.blinkm.getRGBColor((data) -> + console.log("Starting Color: #{ data }") + ) + +Now, every 2 seconds, we'll change the LED color to a random value: + + every 2.second(), -> + my.blinkm.getRGBColor((data) -> + console.log("Current Color: #{ data }") + ) + my.blinkm.fadeToRandomRGB(128, 128, 128) Now that our robot knows what to do, let's get started: