This repository has been archived on 2024-01-30. You can view files and clone it, but cannot push or open issues or pull requests.
trev/nodejs/ar-com/rc.js

24 lines
721 B
JavaScript

var events = require('events'),
util = require('util');
var RC = function (arduino, pin) {
if(!arduino){throw new Error('Arduino must be set');}
this.arduino = arduino;
this.pin = pin && pin || 11;
}
RC.prototype.send = function(tristate) {
var str = '';
for(i = 0; i < tristate.length; i+=2) { str += String.fromCharCode(parseInt(tristate.substr(i,2), 16)); }
this.arduino.write(new Buffer('W' + String.fromCharCode(97 + this.pin) + str,'ascii'));
}
RC.prototype.sendDecimal = function (len, val) {
len = this.arduino.valueToFirstTwo(len);
val = this.arduino.valueToLastFour(val);
arduino.write(new Buffer('W' + String.fromCharCode(97 + this.pin) + len + val,'ascii'));
}
module.exports = RC;