From 1e100f47fafa10357f80945970890927c0d6d4b2 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Tue, 26 Nov 2013 16:49:14 -0800 Subject: [PATCH] Literate coffeescript version of BlinkM example --- examples/blinkm/blinkm.litcoffee | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/blinkm/blinkm.litcoffee diff --git a/examples/blinkm/blinkm.litcoffee b/examples/blinkm/blinkm.litcoffee new file mode 100644 index 0000000..086b941 --- /dev/null +++ b/examples/blinkm/blinkm.litcoffee @@ -0,0 +1,58 @@ +# BlinkM + +For this example, we're going to use the `cylon-firmata` module to blink a light +using BlinkM. + +Before we start, make sure you've got the `cylon-firmata` module installed. + +First, let's import Cylon: + + Cylon = require '../..' + +With Cylon imported, we can start defining our robot. + + Cylon.robot + +Our robot will be using an Arduino, and communicating over the Firmata protocol: + + connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' } + +And we'll have one device, a BlinkM led. + + device: { name: 'blinkm', driver: 'blinkm' } + +We'll now set up our robot's work. + + work: (my) -> + +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: + + my.blinkm.version (version) -> + Logger.info "Started BlinkM version #{version}" + +By default, we'll turn the LED off and assign a boolean that we'll use to +determine if it's on or not: + + my.blinkm.off() + lit = false + +Now, every second, we'll toggle the LED, using the `lit` variable to determine +which state we need to transition the BlinkM to: + + every 1.second(), -> + if lit + lit = false + Logger.info 'on' + my.blinkm.rgb 0xaa, 0, 0 + else + lit = true + Logger.info 'off' + my.blinkm.rgb 0, 0, 0 + +Now that our robot knows what to do, let's get started: + + .start()