Some pure JS examples for the purists

This commit is contained in:
deadprogram 2013-10-28 21:43:27 -07:00
parent b29f911628
commit a95bd2e0ee
3 changed files with 68 additions and 0 deletions

11
examples/blink.js Normal file
View File

@ -0,0 +1,11 @@
var Cylon = require('..');
// Initialize the robot
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();

12
examples/button.js Normal file
View File

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

45
examples/travis.js Normal file
View File

@ -0,0 +1,45 @@
var Cylon = require('..')
var Travis = require('travis-ci')
var travis = new Travis({version: '2.0.0'});
var BLUE = 0x0000ff
var GREEN = 0x00ff00
var RED = 0xff0000
Cylon.robot({
connection: {name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0'},
device: {name: 'sphero', driver: 'sphero'},
work: function(me) {
var user = "hybridgroup"
var name = "cylon"
me.checkTravis = function() {
Logger.info("Checking repo "+user+"/"+name);
me.sphero.setRGB(BLUE, true);
travis.repos(
{ owner_name: user, name: name },
function(err, res) {
if (res.repo != undefined) {
if (res.repo.last_build_state == 'passed') {
me.sphero.setRGB(GREEN, true);
} else if (res.repo.last_build_state == 'failed') {
me.sphero.setRGB(RED, true);
} else {
me.sphero.setRGB(BLUE, true);
}
} else {
me.sphero.setRGB BLUE, true
}
});
}
me.checkTravis();
every((10).seconds(), function() {
me.checkTravis();
});
}
}).start();