'use strict';
var Cylon = require('cylon');
Cylon.robot({
name: 'cybot',
events: ['turned-on', 'turned-off', 'toggle'],
commands: function() {
return {
turn_on: this.turnOn,
turn_off: this.turnOff,
toggle: this.toggle
};
},
connections: {
arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }
},
devices: {
led: { driver: 'led', pin: 13 }
},
work: function() {
after((1).seconds(), function() {
this.turnOn();
}.bind(this));
after((2).seconds(), function() {
this.turnOff();
}.bind(this));
},
turnOn: function() {
this.led.turnOn();
this.emit('turned-on');
},
turnOff: function() {
this.led.turnOff();
this.emit('turned-off');
},
toggle: function() {
this.led.toggle();
this.emit('toggle');
if (this.led.isOn()) {
this.emit('turned-on');
} else {
this.emit('turned-off');
}
}
});
Cylon.api(
'mqtt',
{
broker: 'mqtt://test.mosquitto.org',
port: '3000'
});
Cylon.start();