ribbons.platforms.lego.mindstorms.nxt
Version:
Lego Mindstorms NXT as a Ribbons platform.
30 lines (26 loc) • 715 B
JavaScript
function LegoMindstormsNxt (options) {
var Nxt = require('mindstorms_bluetooth').Nxt;
var nxt = new Nxt(options['serialPort']);
this.Pin = function (pin) {
var ports = {
1: nxt.INPUT_PORT_1,
2: nxt.INPUT_PORT_2,
3: nxt.INPUT_PORT_3,
4: nxt.INPUT_PORT_4
}
if (pin in ports) {
this.port = ports[pin];
} else {
throw new Error('specified pin ' + pin + ' is invalid');
}
}
this.Pin.prototype = {
on: function () {
nxt.set_input_state(this.port, nxt.LIGHT_ACTIVE, nxt.BOOLEANMODE);
},
off: function () {
nxt.set_input_state(this.port, nxt.LIGHT_INACTIVE, nxt.BOOLEANMODE);
}
}
}
module.exports = LegoMindstormsNxt;