add rc module
This commit is contained in:
parent
386ea0c2be
commit
74758e7d00
1 changed files with 21 additions and 0 deletions
21
nodejs/ar-com/rc.js
Normal file
21
nodejs/ar-com/rc.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
|
||||||
|
var RC = function (arduino, pin) {
|
||||||
|
if(!arduino){throw new Error('Arduino must be set');}
|
||||||
|
this.arduino = arduino;
|
||||||
|
this.pin = pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
RC.prototype.send = function(tristate) {
|
||||||
|
var str = '';
|
||||||
|
for(i = 0; i < s.length; i+=2) { str += String.fromCharCode(parseInt(tristate.substr(i,2), 16)); }
|
||||||
|
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'));
|
||||||
|
};
|
Reference in a new issue