Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RC-Switch power socket commands #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/rc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var arduino = require('../')
board, rc;

var board = new arduino.Board({
debug: true
});

var rc = new arduino.RC({
board: board,
pin: "10"
});

board.on('ready', function(){
setTimeout(function() {
// alternative: rc.decimal("123456")
rc.triState("0FFF0FFFFF0F");
}, 1000);
setTimeout(function() {
rc.triState("0FFF0FFFFF00");
}, 2000);
});
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
Sensor: require('./lib/sensor'),
Ping: require('./lib/ping'),
PIR: require('./lib/pir'),
LCD: require('./lib/lcd')
LCD: require('./lib/lcd'),
RC: require('./lib/rc')
};
31 changes: 31 additions & 0 deletions lib/rc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Main RC constructor
* Process options
* Tell the board to set it up
*/
var RC = function (options) {
if (!options || !options.board) throw new Error('Must supply required options to LED');
this.board = options.board;
this.pin = this.board.normalizePin(options.pin || 10);
}

/*
* Send triState code
*/
RC.prototype.triState = function (val) {
var msg = '96' + this.pin + val;
this.board.write(msg);
}

/*
* Send decimal code
* val must be 12 chars or less
*/
RC.prototype.decimal = function (val) {
// at most twelve, null-term if shorter
var terminatedval = (val + '\0').slice(0,12)
var msg = '94' + this.pin + terminatedval;
this.board.write(msg);
}

module.exports = RC;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
{ "name": "Seiya Konno", "email": "[email protected]" },
{ "name": "Nathan Vander Wilt", "email": "[email protected]" },
{ "name": "Adam Brault (&yet)", "email": "[email protected]" },
{ "name": "Emanuele Tessore", "email": "[email protected]" }
{ "name": "Emanuele Tessore", "email": "[email protected]" },
{ "name": "Willi Thiel", "email": "[email protected]" },
{ "name": "Tom Janson", "email": "[email protected]" }
],
"name": "duino",
"description": "Arduino framework for mad scientists",
"version": "0.0.9",
"version": "0.0.10",
"keywords": [
"arduino",
"serial",
Expand Down
Loading