Skip to content

Instantly share code, notes, and snippets.

@zankich
Created March 12, 2014 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zankich/9497951 to your computer and use it in GitHub Desktop.
Save zankich/9497951 to your computer and use it in GitHub Desktop.

####Installation instructions

  • You will need node.js as well as satisfying the dependencies listed here
  • Once you have the required dependencies met, you can install the required node modules with
    $ npm install cylon cylon-gpio cylon-i2c cylon-firmata cylon-sphero cylon-leapmotion
  • Install the leap motion software and sdk

####Arduino blink

//blink.js
var Cylon = require('cylon');

Cylon.robot({
  connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
  device: {name: 'led', driver: 'led', pin: 13},

  work: function(my) {
    every((1).seconds(), function() {my.led.toggle()});
  }
}).start();

####Makey button Image

//makey.js
var Cylon = require('cylon');
 
Cylon.robot({
  connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
  devices: [
    {name: 'led', driver: 'led', pin: 13},
    { name: 'makey', driver: 'makey-button', pin: 2 }
  ],
 
  work: function(my) {
    my.makey.on('push', function() {
      my.led.toggle();
    });
  }
}).start();

####Sphero Color

//sphero_color.js
var Cylon = require('cylon');

Cylon.robot({
  connection: { name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' },
  device: { name: 'sphero', driver: 'sphero' },

  work: function(me) {
    every((1).second(), function() {
      me.sphero.setRGB(Math.floor(Math.random() * 100000));
    });
  }
}).start();

####Leap

//leap.js
var Cylon = require('cylon');

Cylon.robot({
  connection: { name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' },
  device: { name: 'leapmotion', driver: 'leapmotion' },

  work: function(my) {
    my.leapmotion.on('connect', function() {
      Logger.info("Connected");
    });

    my.leapmotion.on('start', function() {
      Logger.info("Started");
    });

    my.leapmotion.on('frame', function(frame) {
      Logger.info(frame.toString());
    });

    my.leapmotion.on('hand', function(hand) {
      Logger.info(hand.toString());
    });

    my.leapmotion.on('pointable', function(pointable) {
      Logger.info(pointable.toString());
    });

    my.leapmotion.on('gesture', function(gesture) {
      Logger.info(gesture.toString());
    });
  }
}).start();

####Leap sphero

//leap_sphero.js
var Cylon = require('cylon');

Cylon.robot({
  connections: [
    { name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' },
    { name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' }
  ],
  devices: [
    { name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion' },
    { name: 'sphero', driver: 'sphero', connection: 'sphero'}
  ],
  work: function(my) {
    my.leapmotion.on('hand', function(hand) {
      var r = hand.palmY.fromScale(100, 600).toScale(0, 255)
      if r != void(0) {
        my.sphero.setRGB(r, 0, 0);
      }
    });
  }
}).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment