Skip to content

Commit fb115ef

Browse files
ni-ctjanson
authored andcommitted
Added support for rc-switch
decimal RC code support Fixed problem with single digit pins ni-c/heimcontrol.js#2
1 parent 86981ed commit fb115ef

7 files changed

Lines changed: 1085 additions & 28 deletions

File tree

examples/rc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var arduino = require('../')
2+
board, rc;
3+
4+
var board = new arduino.Board({
5+
debug: true
6+
});
7+
8+
var rc = new arduino.RC({
9+
board: board,
10+
pin: "10"
11+
});
12+
13+
board.on('ready', function(){
14+
setTimeout(function() {
15+
// alternative: rc.decimal("123456")
16+
rc.triState("0FFF0FFFFF0F");
17+
}, 1000);
18+
setTimeout(function() {
19+
rc.triState("0FFF0FFFFF00");
20+
}, 2000);
21+
});

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ module.exports = {
88
Sensor: require('./lib/sensor'),
99
Ping: require('./lib/ping'),
1010
PIR: require('./lib/pir'),
11-
LCD: require('./lib/lcd')
11+
LCD: require('./lib/lcd'),
12+
RC: require('./lib/rc')
1213
};

lib/rc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Main RC constructor
3+
* Process options
4+
* Tell the board to set it up
5+
*/
6+
var RC = function (options) {
7+
if (!options || !options.board) throw new Error('Must supply required options to LED');
8+
this.board = options.board;
9+
this.pin = this.board.normalizePin(options.pin || 10);
10+
}
11+
12+
/*
13+
* Send triState code
14+
*/
15+
RC.prototype.triState = function (val) {
16+
var msg = '96' + this.pin + val;
17+
this.board.write(msg);
18+
}
19+
20+
/*
21+
* Send decimal code
22+
* val must be 12 chars or less
23+
*/
24+
RC.prototype.decimal = function (val) {
25+
// at most twelve, null-term if shorter
26+
var terminatedval = (val + '\0').slice(0,12)
27+
var msg = '94' + this.pin + terminatedval;
28+
this.board.write(msg);
29+
}
30+
31+
module.exports = RC;

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
{ "name": "Seiya Konno", "email": "nulltask@gmail.com" },
77
{ "name": "Nathan Vander Wilt", "email": "nate@calftrail.com" },
88
{ "name": "Adam Brault (&yet)", "email": "contact@andyet.com" },
9-
{ "name": "Emanuele Tessore", "email": "setola@gmail.com" }
9+
{ "name": "Emanuele Tessore", "email": "setola@gmail.com" },
10+
{ "name": "Willi Thiel", "email": "ni-c@ni-c.de" },
11+
{ "name": "Tom Janson", "email": "priv.tom.janson+duino@gmail.com" }
1012
],
1113
"name": "duino",
1214
"description": "Arduino framework for mad scientists",
13-
"version": "0.0.9",
15+
"version": "0.0.10",
1416
"keywords": [
1517
"arduino",
1618
"serial",

0 commit comments

Comments
 (0)