Skip to content

Instantly share code, notes, and snippets.

@zankich
Forked from chrismatthieu/gist:8c6b8b3731d3ebd03686
Last active August 29, 2015 14:16
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/e3deb3b6dd51ae9b2ec0 to your computer and use it in GitHub Desktop.
Save zankich/e3deb3b6dd51ae9b2ec0 to your computer and use it in GitHub Desktop.
var Cylon = require('cylon');
Cylon.robot({
connections: {
arduino: { adaptor: 'firmata', port: '/dev/tty.usbmodem1411' },
skynet: { adaptor: 'skynet', uuid: "db895340-c344-11e4-9f09-df7578d68eac", token: "d0a9f0d7e321657a38d25dd492492ffed0baf773" }
},
work: function(my) {
my.skynet.on('message', function(data) {
data.forEach(function(o) {
var pin = (o.pin).toString();
if (my.devices[pin] === undefined) {
my.device(pin, { driver: "direct-pin", pin: o.pin, connection: "arduino" });
my.devices[pin].start();
}
if (o.mode === 0) {
my.devices[pin].digitalRead(function(err, val) {
console.log(val);
});
} else if (o.mode === 1) {
my.devices[pin].digitalWrite(o.value);
}
});
});
}
}).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment