2014-02-20 12:06:51 +08:00
|
|
|
var Cylon = require('../..');
|
|
|
|
|
|
|
|
Cylon.robot({
|
|
|
|
connections: [
|
|
|
|
{ name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
2014-03-06 04:50:39 +08:00
|
|
|
{ name: 'skynet', adaptor: 'skynet',
|
|
|
|
uuid: "96630051-a3dc-11e3-8442-5bf31d98c912", token: "2s67o7ek98pycik98f43reqr90t6s9k9" }
|
2014-02-20 12:06:51 +08:00
|
|
|
],
|
|
|
|
|
2014-03-06 04:50:39 +08:00
|
|
|
device: { name: 'led13', driver: 'led', pin: 13, connection: 'arduino' },
|
2014-02-20 12:06:51 +08:00
|
|
|
|
|
|
|
work: function(my) {
|
2014-03-06 04:50:39 +08:00
|
|
|
Logger.info("Skynet is listening...");
|
|
|
|
|
2014-03-04 01:34:39 +08:00
|
|
|
my.skynet.on('message', function(data) {
|
2014-02-20 12:06:51 +08:00
|
|
|
Logger.info(data);
|
|
|
|
var data = JSON.parse(data);
|
2014-03-04 01:34:39 +08:00
|
|
|
if(data.message.red == 'on') {
|
2014-03-06 04:50:39 +08:00
|
|
|
my.led13.turnOn()
|
2014-02-20 12:06:51 +08:00
|
|
|
}
|
2014-03-04 01:34:39 +08:00
|
|
|
else if(data.message.red == 'off') {
|
2014-03-06 04:50:39 +08:00
|
|
|
my.led13.turnOff()
|
2014-02-20 12:06:51 +08:00
|
|
|
}
|
|
|
|
});
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-02-20 12:06:51 +08:00
|
|
|
}
|
|
|
|
}).start();
|