cylon/examples/skynet/skynet-blink.markdown

51 lines
1.2 KiB
Markdown
Raw Normal View History

2014-02-21 08:29:18 +08:00
# Skynet Blink
2014-03-28 00:31:56 +08:00
2014-02-21 08:29:18 +08:00
First, let's import Cylon:
2014-03-28 00:31:56 +08:00
var Cylon = require('../..');
2014-02-21 08:29:18 +08:00
Now that we have Cylon imported, we can start defining our robot
2014-03-28 00:31:56 +08:00
Cylon.robot({
2014-02-21 08:29:18 +08:00
Let's define the connections and devices:
connections: [
2014-03-28 00:31:56 +08:00
{
name: 'arduino',
adaptor: 'firmata',
port: '/dev/ttyACM0'
},
{
name: 'skynet',
adaptor: 'skynet',
uuid: "96630051-a3dc-11e3-8442-5bf31d98c912",
token: "2s67o7ek98pycik98f43reqr90t6s9k9"
}
],
device: { name: 'led13', driver: 'led', pin: 13, connection: 'arduino' },
2014-02-21 08:29:18 +08:00
Now that Cylon knows about the necessary hardware we're going to be using, we'll
tell it what work we want to do:
2014-03-28 00:31:56 +08:00
work: function(my) {
2014-05-14 10:06:40 +08:00
console.log("Skynet is listening...");
2014-03-28 00:31:56 +08:00
my.skynet.on('message', function(data) {
2014-05-14 10:06:40 +08:00
console.log(data);
2014-03-28 00:31:56 +08:00
var data = JSON.parse(data);
if(data.message.red == 'on') {
my.led13.turnOn()
}
else if(data.message.red == 'off') {
my.led13.turnOff()
}
});
}
2014-02-21 08:29:18 +08:00
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
2014-03-28 00:31:56 +08:00
}).start():