var cylon = require('cylon'); cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, device: {name: 'led', driver: 'led', pin: 13 }, }) .on('ready', function(bot) { setInterval(function() { bot.led.toggle(); }, 1000); }) .start();
var cylon = require('cylon'); cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, devices: [ { name: 'sensor', driver: 'analogSensor', pin: 0 }, { name: 'led', driver: 'led', pin: 3 } ] }) .on('ready', function(bot) { bot.sensor.on('analogRead', function(val) { brightness = val.fromScale(0, 1024).toScale(0, 255) | 0; console.log('brightness => ', brightness); bot.led.brightness(brightness) }); }) .start();
var cylon = require('cylon'); cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, devices: [ { name: 'sensor', driver: 'analogSensor', pin: 0 }, { name: 'blinkm', driver: 'blinkm' } ] }) .on('ready', function(bot) { bot.blinkm.stopScript(); bot.sensor.on('analogRead', function(val) { brightness = val.fromScale(0, 1024).toScale(0, 255) | 0; console.log('brightness => ', brightness); bot.blinkm.goToRGB(brightness, brightness, brightness); }); }) .start();
var cylon = require('cylon'); cylon.robot({ connection: { name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' }, device: { name: 'sphero', driver: 'sphero' }, }) .on('ready', function(bot) { setInterval(function() { bot.sphero.roll(60, Math.floor(Math.random() * 360)); }, 1000); }) .start();
var Cylon = require("cylon"); var Green = 0x0000FF, Red = 0xFF0000; var bots = { 'Thelma': '/dev/rfcomm0', 'Louise': '/dev/rfcomm1', 'Grace': '/dev/rfcomm2', 'Ada': '/dev/rfcomm3' }; Object.keys(bots).forEach(function(name) { var port = bots[name]; var robot = Cylon.robot({ name: name, connection: { name: 'sphero', adaptor: 'sphero', port: port }, device: { name: 'sphero', driver: 'sphero' } }); robot.move = function() { robot.sphero.roll(60, Math.floor(Math.random() * 360)); }; robot.born = function() { robot.contacts = 0; robot.age = 0; robot.life(); robot.move(); }; robot.life = function() { robot.alive = true; robot.sphero.setRGB(Green); }; robot.death = function() { robot.alive = false; robot.sphero.setRGB(Red); robot.sphero.stop(); }; robot.enoughContacts = function() { return robot.contacts >= 2 && robot.contacts < 7; }; robot.birthday = function() { robot.age += 1; if (robot.alive) { console.log("Happy birthday, " + robot.name + ". You are " + robot.age + " and had " + robot.contacts + " contacts."); } if (robot.enoughContacts()) { if (!robot.alive) { robot.born(); } } else { robot.death(); } robot.contacts = 0; }; robot.on('ready', function() { robot.born(); robot.sphero.on('collision', function() { robot.contacts += 1; }); every((3).seconds(), function() { if (robot.alive) { robot.move(); } }); every((10).seconds(), function() { robot.birthday(); }); }); }); Cylon.start();