A Node.js SDK for programming the LEGO® Powered Up platform.
Disclaimer: LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this software.
Please install the @powered-up/api
package as described
here.
The following example uses a Smart Move Hub (included in the LEGO® Boost Set 17101) and activates the built-in motor A while the button is held down:
// @ts-check
const {SmartMoveRobot} = require('@powered-up/api');
const {autorun} = require('mobx');
const moveRobot = new SmartMoveRobot();
autorun(() => {
const {buttonPressed, encodedMotorA, rgbLight} = moveRobot;
if (!encodedMotorA || !rgbLight) {
return;
}
if (buttonPressed) {
rgbLight.setColor({red: 0, green: 255, blue: 0});
encodedMotorA.runWithPower(100);
} else {
rgbLight.setColor({red: 255, green: 0, blue: 0});
encodedMotorA.brake();
}
});
You can find some more examples in the demo package.
Smart Move Hub 2 I/O (Robot) | Smart Hub 2 I/O (Robot) | |
---|---|---|
Button | ✅ Supported | ✅ Supported |
VoltageSensor | ✅ Supported | ✅ Supported |
CurrentSensor | ✅ Supported | ✅ Supported |
RGBLight | ✅ Supported | ✅ Supported |
InternalEncodedMotor | ✅ Supported | ❌ N/A |
InternalTiltSensor | ❌ N/A | |
Motor | ✅ Supported | ✅ Supported |
EncodedMotor | ✅ Supported | |
VisionSensor |
A reactive library for controlling LEGO® Powered Up devices.
A reactive library for managing BLE connections to LEGO® Powered Up hubs.
A partial implementation of the LEGO® Powered Up BLE protocol in JavaScript.
Copyright (c) 2018-present, Clemens Akens. Released under the terms of the MIT License.