From 74758e7d00bf9e688ce6de67be90cc70fb6c9b4d Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Fri, 29 Jan 2016 21:33:26 +0100 Subject: [PATCH] add rc module --- nodejs/ar-com/rc.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 nodejs/ar-com/rc.js diff --git a/nodejs/ar-com/rc.js b/nodejs/ar-com/rc.js new file mode 100644 index 0000000..df9836b --- /dev/null +++ b/nodejs/ar-com/rc.js @@ -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')); +}; \ No newline at end of file