UNPKG

ev3js

Version:

LEGO Mindstorms EV3 API for Node.js

35 lines (26 loc) 781 B
var fs = require('fs'); var LED = function(color, position){ this.color = color; this.position = position; this.max = this.get(this.MAX); }; LED.GREEN = 'green'; LED.RED = 'red'; LED.LEFT = 'left'; LED.RIGHT = 'right'; (function(){ this.PATH = '/sys/class/leds/ev3'; this.MAX = 'max_brightness'; this.CURRENT = 'brightness'; this.max = 1; this._filePath = function(name){ return [this.PATH, this.color, this.position].join(':') + '/' + (name || this.CURRENT); }; this.get = function(name){ return fs.readFileSync(this._filePath(name)) / this.max; }; this.set = function(value){ fs.writeFile(this._filePath(), value * this.max | 0, function(){}); }; }.bind(LED.prototype))(); module.exports = LED;