diff --git a/nodejs/ar-com/sensor.js b/nodejs/ar-com/sensor.js new file mode 100644 index 0000000..ee74a8e --- /dev/null +++ b/nodejs/ar-com/sensor.js @@ -0,0 +1,31 @@ +var events = require('events'), + util = require('util'); + +var Sensor = function (arduino, pin) { + if(!arduino || !pin) {console.log("Arduino or pin not set!");} + this.arduino = arduino; + this.pin = pin; + + this.board.on('data', function (message) { + var m = message.slice(0, -1).split('::'), + err = null; + + if (m.length != 2 && this.pin != m[0]) { + return; + } + + this.emit('read', err, m[1]); + + }.bind(this)); + +} + +util.inherits(Sensor, events.EventEmitter); + +Sensor.prototype.trigger = function() { + + this.arduino.write(new Buffer('Y' + String.fromCharCode(this.pin) + '000000', 'ascii')); + +}; + +module.exports = IR; \ No newline at end of file